1

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?

  • 1
    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 7 '17 at 13:52
  • @Satō Katsura So in my case, cat has set itself to a new group? – user259392 Nov 7 '17 at 13:55
  • 2
    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 7 '17 at 14:10
  • 1
    Shells do this as part of job handling -- unix.stackexchange.com/questions/363126/… – thrig Nov 7 '17 at 15:41

Your Answer

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

Browse other questions tagged or ask your own question.