:: [DNG] Is the bash man page wrong (j…
Startseite
Nachricht löschen
Nachricht beantworten
Autor: Steffen Dettmer
Datum:  
To: Dng
Betreff: [DNG] Is the bash man page wrong (jobs -p)?
Hi,

man bash says:

       jobs -x command [ args ... ]
              -p     List only the process ID of the job's process group
leader.


and this is true for interactive shells (or possibly better: when job
control is enabled), but for non-interactive shells, namely scripts, it is
not:

$ echo "sleep 1h & sleep 2h & jobs -p ; ps xao pid,pgid,user,tty,comm |grep
sleep" > jobs.bash
$ chmod +x jobs.bash
$ ./jobs.bash
20355
20356
20355 20354 sdettmer pts/4    sleep
20356 20354 sdettmer pts/4    sleep


the process group of the sleep is not an own, but the process group of the
running non-interactive shell (which is stated in man bash in the job
control documentation). Here, the process group leader (which is supposed
to be printed) is neither 20355 nor 20356, as "jobs -p" says, but it is
"20354" for both jobs. The "process ID of the job's process group leader",
which should be printed by jobs, would be the process ID of the shell, $$,
in this particular case.

I assume jobs -p prints the process ID of the first process in a pipe or so?

What is it showing? How can I know and distinguish whether I got a pgrp or
a pid?

(this makes "pkill -g 20355 ; pkill -g 20356" fail, as the passed IDs are
no process group IDs, but process IDs. My usecase is to terminate all
background activity started by a cascade of scripts, but not to kill a
running interactive shell or even the X session, as stack overflow answers
suggest)

Steffen