1

I have a bash script script1:

#! /bin/bash
evince 

and another script script2

#! /bin/bash
evince &

When I run

./script2

the bash process exits immediately after putting evince into background, leaving the evince process continue running.

When I run

./script1 &

the bash process waits for evince to finish running.

If I kill the bash process, the bash process exits and also terminates the evince process.

I was wondering why the termination of the bash process doesn't affect the evince process in the second script, but does in the first script?

Could you explain in terms of system calls such as fork(), exit() and wait()?

Thanks.

This is related to Why can this script running in the background survive `kill` and termination of the invoking shell?, but here I want to learn the basic general case.

1 Answer 1

0

If you did really only kill the shell, you should make a bug report against bash.

Since modern shells automatically enable job control for interactive shells,

./script1&

creates a new job with an own process group id.

The shell waits on the program evince and if you call:

kill -9 $!

only the shell will be killed and evince will continue to run.

If you however call:

kill %1

This kills the whole job including evince.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .