Commit ba7bb38
committed
Fix handling process groups when initial process is not running anymore
One can set the `kill_whole_group` attribute to make the `stop` function
of `ReadWriteProcess` stop the whole process group. This works in general
but there are a few flaws this change addresses:
* Make `is_running` consider the whole process group as well. Otherwise,
when the initial process is not running anymore `stop` returns early,
even though there are still other processes left in the group.
* Avoid the use of `getpgrp` in the `stop` function. This function needs
the PID to be still valid but this might not be the case when the initial
process is not running anymore. The group ID is simply the PID of the
initial process so we can just use that. (Assuming the the process group
was created by invoking `setpgrp(0, 0)` in the code callback.)
I tested this by creating a simple script that will leave a leftover
process¹. In the code callback I executed `setpgrp(0, 0)` followed by
`exec(…)` on that script. Without this change the a process is left behind
when calling `stop` (see `ps -aux | grep 'sleep infinity'`). With this
change the process is correctly cleaned up. I used existing code of openQA
(`isotovideo.pm`) to test this.
Related issue: https://progress.opensuse.org/issues/170209
---
¹
```
#!/bin/bash
sleep infinity &
```1 parent f04eb4e commit ba7bb38
1 file changed
Lines changed: 5 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
403 | 403 | | |
404 | 404 | | |
405 | 405 | | |
406 | | - | |
| 406 | + | |
| 407 | + | |
407 | 408 | | |
408 | 409 | | |
409 | 410 | | |
| |||
519 | 520 | | |
520 | 521 | | |
521 | 522 | | |
522 | | - | |
523 | 523 | | |
524 | 524 | | |
525 | 525 | | |
526 | 526 | | |
527 | 527 | | |
528 | 528 | | |
529 | 529 | | |
530 | | - | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
531 | 533 | | |
532 | 534 | | |
533 | 535 | | |
| |||
0 commit comments