0

Saying that I have two bash scripts as below:

#!/bin/bash
# this is test.sh

./test2.sh

and

#!/bin/bash
# this is test2.sh
while :
do
    sleep 2
done

After executing the test.sh with the command ./test.sh &, a process group has been created. I can see this group with the command ps xao pid,ppid,pgid,comm | grep test, which gives me the output as below:

16429 15818 16429 test.sh
16430 16429 16429 test2.sh

As we can see, ppid(test2)=pid(test)=16429 and pgid(test2)=pgid(test)=16429. So we got a process group and its id of leader is 16429. Everything works as expected.

Then I execute kill -9 16429 to kill the process test.sh.

Now the command ps xao pid,ppid,pgid,comm | grep test gives me the output:

16430     1 16429 test2.sh

However, now there doesn't exist any process, whose pid is 16429. So it means that we have a process group without a leader. Is this normal?

  • 2
    Yes, it's absolutely OK. The easiest way to create such a process is to run (in an interactive shell with job control) a command like sh -c 'sleep 3600 &'. Also look here and here. – mosvy May 27 at 8:02

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.