Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

this question is a follow-up to: How to suspend and resume processes

I have started firefox from a bash session in gnome-terminal.

The process tree looks like this:

$ ps -e -o pid,ppid,cmd -H
 1828     1   gnome-terminal
26677  1828     bash
27980 26677       /bin/sh /usr/lib/firefox-3.6.15/firefox
27985 27980         /bin/sh /usr/lib/firefox-3.6.15/run-mozilla.sh /usr/lib/firefox-3.6.15/firefox-bin
27989 27985           /usr/lib/firefox-3.6.15/firefox-bin
28012 27989             /usr/lib/firefox-3.6.15/plugin-container /usr/lib/adobe-flashplugin/libflashplayer.so 27989 plugin true

When I hit CTRL+Z in bash, it will suspend firefox. When I issue the command bg (or fg) it will resume firefox. This is as expected.

When I issue the command kill -s SIGTSTP 27980 in another terminal, it will print the line [1]+ Stopped firefox in the first terminal (just like when i hit CTRL+Z), but it does not suspend firefox. I asume it only suspends the shell script.

When I issue the command kill -s SIGTSTP 27989 (note the PID) in another terminal, it will suspend firefox. The first terminal does not take note of this.

How does bash suspend the entire process tree? does it just traverse the tree and SIGTSTP all of the children?

share|improve this question
2  
See also Difference between process group and job?. –  Gilles Mar 17 '11 at 19:53
    
You should add pgid to your ps command to see the process groups @geekosaur is talking about. –  ninjalj Mar 17 '11 at 22:54
add comment

1 Answer 1

up vote 14 down vote accepted

Shell jobs live in "process groups"; look at the PGRP column in extended ps output. These are used both for job control and to determine who "owns" a terminal (real or pty).

POSIX (taken from System V) uses a negative process ID to indicate a process group, since the process group is identified by the first process in the group ("process group leader"). So you would use ps to determine the process group, then kill -s TSTP "-$pgrp". (Try ps -u"$USER" -opid,ppid,pgrp,cmd.)

In your process tree, the process group starts with the firefox script launched by bash, so the process group would be 27980 and the command would be kill -s TSTP -27980.

Naturally, to resume the process group, issue kill -s CONT -- -27980.

share|improve this answer
6  
By the way, bash isn't doing the SIGTSTP when you type ^Z; since firefox's process group is the terminal's current process group, the terminal driver (pedantically, line discipline) sends the SIGTSTP to all the processes in that process group. bash is just waitpid()ing on it (and any other jobs). Other terminal signals, such as ^C and ^\ work the same way. (meta: SE hates that ctrl-backslash..) –  geekosaur Mar 17 '11 at 19:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.