Understanding system processes through Python scripts

Source: Internet
Author: User

From socket import * from time import ctimeimport OS, sys # sys defines the process exit method HOST = 'localhost' # defines the host port = 21567 # defines the PORT number BUFSIZ = 1024 # defines the buffer ADDR = (HOST, PORT) # define tcpSerSock = socket (AF_INET, SOCK_STREAM) # generate TCP SockettcpSerSock. bind (ADDR) # bind the Socket to the tcpSerSock. listen (5) # listen to the request while True: # define an infinite loop (more and more like shell) print "waiting .... "try: # The tcpSerSock statement is destroyed in the generation process. If this exception is not caught, a program error will occur! TcpCliSock, addr = tcpSerSock. accept () failed T: # capture all exceptions sys. exit (0) # exit the current process as long as the blocking failure is captured. (Only the generated process can cause blocking failure. Only the words tcpSerSock are destroyed in the generated process.) if OS. fork (): # If the operation in the main process passes else: # If the operation in the derived process prints 'Con from: ', addr while True: data = tcpCliSock. recv (BUFSIZ) if not data: tcpSerSock. close () # destroy tcpSerSock break # Jump out of the loop! TcpCliSock. send ('[% s] % s' % (ctime (), data) tcpSerSock. close () # This sentence will never be executed!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.