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.

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: https://unix.stackexchange.com/a/139230/181255

Also see:

man credentials
  • ok, can i make gedit and firefox have the same pgid? – alkabary Feb 23 at 23:40
  • @alkabary See my update. – Tomasz Feb 23 at 23:45

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.