3

I always thought that a child process will be in the same process group as the parent process. But I have read the following from here:

if you run some_app from the shell, the shell creates a new process group for it, and makes that the foreground process group of the session.

I made bash execute cat, and I found out that cat indeed has a different process group id than bash. Is this a bash only behavior to have the child process be in a different group?

user259392
  • 83
  • 1
  • 5
  • 2
    After `fork()` the child process is in the same group as the parent. The child can set itself to a new group (perhaps before `exec()`-ing something else), or it can stay within the parent's group. It all depends on what you want to achieve. – Satō Katsura Nov 07 '17 at 13:52
  • @Satō Katsura So in my case, `cat` has set itself to a new group? – user259392 Nov 07 '17 at 13:55
  • 3
    No, `bash` did a `fork()`, then the child set itself to a new group, then the same child `exec()`-ed your `cat`. – Satō Katsura Nov 07 '17 at 14:10
  • 1
    Shells do this as part of job handling -- https://unix.stackexchange.com/questions/363126/why-is-process-not-part-of-expected-process-group – thrig Nov 07 '17 at 15:41

0 Answers0