How do I start and stop a Linux program using the subprocess module in Python? How do I start and stop a Linux program using the subprocess module in Python? python python

How do I start and stop a Linux program using the subprocess module in Python?


I don't know why you want to run Xvfb as root. Your usual X server only needs to run as root (on many but not all unices) only so that it can access the video hardware; that's not an issue for Xvfb by definition.

tempdir = tempfile.mkdtemp()xvfb = subprocess.Popen(['Xvfb', ':99', '-nolisten', 'tcp', '-fbdir', tempdir])

When you terminate the X server, you may see a zombie process. This is in fact not a process (it's dead), just an entry in the process table that goes away when the parent process either reads the child's exit status or itself dies. Zombies are mostly harmless, but it's cleaner to call wait to read the exit status.

xvfb.terminate()# At this point, `ps -C Xvfb` may still show a running process# (because signal delivery is asynchronous) or a zombie.xvfb.wait()# Now the child is dead and reaped (assuming it didn't catch SIGTERM).


I assume you can parametrize your system to allow any user to launch Xvfb as explained here solving all your problems

EDITthe correct command line is

sudo chmod u+s `which Xvfb`