I am looking at a scenario where I want to run a program / command with
sudo as part of a software test. The commands are launched from a Python script based on the
subprocess module. I am attempting to avoid having to run the entire test suite with super user privileges.
Let's say for the purpose of this example, it's
top. My command starts a few sub-processes of its own and may run into a deadlock. After a timeout, I want to kill it (and its children). The obvious solution appears to be to make my command head of a new session / process group, allowing me to kill it and its children altogether at once. What I can NOT figure out is how to make this work with
sudo. In my case,
sudo is always password protected without exception and I want keep it this way ... if possible.
- Works, but does NOT spawn a new process group:
sudo setsid top
- Problematic - hard to get the root password in in a safe and sound manner:
setsid sudo top
I did not manage to make (3) work in a clean way. I messed around with
What surprised me was the fact that (2) actually runs but does NOT give me the desired new process group.
systemd─┬─ ... ├─kdeinit5─┬─ ... │ └─yakuake─┬─2*[bash] │ ├─bash───sudo───top │ ├─bash───pstree ...