A recent gadget need to use the Python word process, look at the Python api,subprocess module can be implemented, and quite simple
To implement a simple self process, you need only
Import sys, OS, subprocess p = subprocess. Popen (["LS", "L"], Shell=false, Stdin=none, Stdout=none, stderr=none) print p.pid print P.returncode
At this point, the PID will be the ID number of the subprocess, and ReturnCode will be none if the child process is rolled out normally.
You can also use the following code to create a child process
Import sys, OS, subprocess retcode=subprocess.call (["LS", "L"], Shell=false, Stdin=none, Stdout=none, Stderr=none) Print Retcode
At this point, if the subprocess is rolled out normally, Retcode will be 0.
In addition, you can set the stdout and stderr in the method parameters to subprocess If you do not want to output the print information for the created child process. PIPE.
Here is a small example of creating a subprocess P1 and then creating a subprocess P2 to end P1 execution.
Import sys, OS, subprocess p1 = subprocess. Popen (["Sleep", "M"], Shell=false, Stdin=none, Stdout=none, stderr=none) print p1.pid print p1.returncode P2 = subprocess . Popen (["Kill", str (P1.PID)], Shell=false, Stdin=none, Stdout=none, stderr=none) print p2.pid print P2.returncode