1

I am trying to get my mind straight as to how all these things are put together. For example with this script:

#!/bin/bash

. script1
./script2
. script3 &
./script4 &

sleep 5

How do the PIDs look like? What is a separate process and what isn't? Is background process the same as a subshell?

3
  • Seems like you forgot to ask about source script5 and that was what I was looking for. Or else you might want to remove 'source' from the title...
    – sage
    Aug 9, 2015 at 16:44
  • source is the same as the standalone-dots I have in the example.
    – Pithikos
    Aug 11, 2015 at 10:52
  • Wow! more on that... Thanks!
    – sage
    Aug 21, 2015 at 16:18

1 Answer 1

2

. script1 -- not a separate process; script1 is executed in the current shell. see help .

./script2 -- just like calling any external command, forks a new process and waits for completion

. script3 & -- yes, a separate process. An example:

$ cat script3
sleep 300
$ . script3 &
[1] 15136
$ echo $$
15102
$ ps -ef | grep $$
jackman  15102 32659  0 09:43 pts/0    00:00:00 bash
jackman  15136 15102  0 09:44 pts/0    00:00:00 bash
jackman  15157 15102  0 09:44 pts/0    00:00:00 ps -ef
jackman  15158 15102  0 09:44 pts/0    00:00:00 grep --color=auto 15102

See the bash manual, Lists of commands:

If a command is terminated by the control operator ‘&’, the shell executes the command asynchronously in a subshell.

./script4 & -- yes, a separate process.

You must log in to answer this question.

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