The python script listens to the port and processes the incoming stream. If the information on the socket did not arrive more than the N time, then the error socket.timeout is sock.settimeout(N) function is used for this). Communication breaks are not frequent, so the program runs through the subprocess.Popen program in the handler, which sends information to another machine that the connection was interrupted.

The problem is that the processing script does not have to wait for the completion of the child program (which is what happens in principle), but it does not read the return code generated by the program. As a result, zombie processes flood the system ( Linux ).

It was decided this way - the SIGCHLD signal was simply ignored in the main process. Are there any other ways to generate / ignore / read the status of a spawned program without using signals and waiting for its completion? It is advisable to run in such a way as to release the daughter program to free floating and forget about it. The writing language of the child program is not important.

  • Specify, do you still want to get the status of completion or not (launched and forgot about this process)? - avp
  • @avp, I would very much like the main program to not interrupt its execution flow at all (without signal processing, without reading the status). If this is not possible, then any decision is welcomed in which the main program will be executed without waiting for the child program, and without zombie processes. So far, a solution has been found only with signals, but they interrupt the flow of execution after all. - borat_brata
  • one
    2 nested forks. In the second (internal) free swimming is performed. The 1st (external) immediately returns. The main program will come 1st fork (this almost immediately) and works on. I do not know how to spell it on python, but if you are interested in C, I can write an example. - avp
  • one
    1- What is the problem with signal(SIGCHLD, SIG_IGN) ? (posix) 2- do you really see a lot of zombies or just guess? (subprocess automatically collects the code of completed processes when you try to start a new one) - jfs
  • @jfs with signal (SIGCHLD, SIG_IGN) no problem. This method, on the contrary, helps to get rid of zombies. Other solutions and approaches were interesting. Immediately after the completion of the subsidiary, he became a zombak and did not disappear (did not disappear for a long time). The launch of a new process was not waiting. Accordingly, the conclusion was made about the rest. - borat_brata

1 answer 1

subprocess.Popen() allows you to solve the problem of zombie processes. The subprocess module, before launching a new process, collects the codes of the already-tested applications, but the zombie process itself will exist as long as there is a variable that is the result of subprocess.Popen() .