Dealing with processes as a Unix/Linux systems administrator is a fact of life. You need to know about startup scripts, run levels, daemons, cron jobs, long-running processes, concurrency, and a host of other issues. Fortunately, Python makes dealing with processes quite easy. Since Python 2.4, Subprocess has been the one-stop shop module that allows you to spawn new processes and talk to standard input, standard output, and standard error. While talking to a processes is one aspect of dealing with processes, it is also import to understand how to deploy and manage long-running processes as well.
With Python 2.4 came subprocess, which takes the place of several older modules:
popen2 commands. Subprocess is a revolutionary change
for systems administrators and developers who need to deal with processes
and “shelling out.” It is now a one-stop shop for many things dealing with
processes and it may eventually include the ability to manage a flock of
Subprocess might just be the single most important module for a systems administrator, as it is the unified API to “shelling out.” Subprocess is responsible for the following things in Python: spawning new processes connecting to standard input, connecting to standard output, connecting to error streams, and listening to return codes.
To whet your appetite, let’s use the KISS principle (Keep It Simple Stupid), and do the absolute simplest ...