2

Intro: I have a daemon, which spawn processes and I have to stop it all gracefully. The solution I found on web based on pgid:

group_id=$(ps -o pgid= $(cat $pidfile))
if [ ! -z $group_id ]; then
        kill -- -$group_id
    success
fi

I was wondered how it works. And the first thing which I got stuck with is getting group_id. I can't get what's going here:

$ ps -o pgid= 21814
21813

$ ps -o pgid=21814
21814
3525
5180

But it seems, like I really need that first example with space after "=":

$ pstree -p | grep 21814
     |-python(21814)-+-python(21815)-+-{python}(21813)

Can anyone explain what's going on here? What I get as output of that examples?

1 Answer 1

2

The equal symbol following a format flag (-o format) suppress the printing of the header that names the columns of option produced as the output. This enables testing for null (empty) results.

By default, ps selects all processes with the same effective user ID as the current user of the terminal session. Specifying the PID of interest after the = symbol infers that the header line contains that PID. The other processes reported are those for you terminal session --- bash and the ps process itself. You can see this if you do:

ps -o comm,pgid=21814

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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