To background itself, that application forks a child process and exits the parent. The shell knows of the parent process as that's the one it has forked itself before executing the command itself, but it has no visibility on the children or grand-children that that process may have spawned.
A simpler example of such a backgrounding command would be:
$ sh -c 'ps -j; sleep 10 &'
PID PGID SID TTY TIME CMD
6562 6562 14469 pts/13 00:00:00 sh
6563 6562 14469 pts/13 00:00:00 ps
14469 14469 14469 pts/13 00:00:00 zsh
My zsh
knows about that sh
process and its process group.
However, all it sees is that 6562 process exiting. It has no way to know that 6562 process has spawned a 6563 one.
$ ps -j
PID PGID SID TTY TIME CMD
6564 6562 14469 pts/13 00:00:00 sleep
6565 6565 14469 pts/13 00:00:00 ps
14469 14469 14469 pts/13 00:00:00 zsh
However, you can see the process running sleep
is also in that 6562 process group (though, there's nothing stopping commands start new process groups, or even sessions (as daemons typically do)).
Those process groups are only created when the shell is interactive though.
Another thing you could do is:
cmd | cat &
wait
If the processes that cmd spawns don't close their stdout, then cat
won't die until they have all died.
ps
has two syntaxes, the BSD and the System V syntax. If you start your options with a hyphen, you are using System V syntax. The w
flag is a BSD syntax flag. In BSD syntax, you can just specify the process ID without any option. So I think the command you just want is:
ps ww 2180 2182
(where 2180, 2182 are example PIDs).
Best Answer
The -o command is additive, so just do multiple of those:
The problem is that you'll get some whitespace around the PID as its right-justified. You can see the 4158 above has a space after the pipe.