1

I am learning how to use the killpg syscall. So for an experiment, I want to start two new processes with the same pgid and then attempt to kill them using killpg.

I read about setsid so I tried something like:

setsid gedit & firefox &

But the two processes: gedit and firefox ended up having two different pgids.

alkabary
  • 1,429
  • 5
  • 19
  • 37

1 Answers1

1

Open Firefox and a few tabs in it if you can. Then do this:

ps o pid,ppid,pgid,sid,comm

You should see something like this:

  PID  PPID  PGID   SID COMMAND
 5121 25145  2628  2628 Web Content
 5881 25145  2628  2628 Web Content
25145     1  2628  2628 firefox-esr

Or use a subshell to spawn background processes:

$ (sleep 100& gedit&)
$ ps o pid,ppid,pgid,sid,comm
  PID  PPID  PGID   SID COMMAND
 6365  2618  6364 27631 sleep
 6366  2618  6364 27631 gedit

Here's a good explanation why a subshell and what's going on: Why is the PGID of my child processes not the PID of the parent?

Also see:

man credentials
Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164