Search code examples
bashsleeppid

bash - why does ( cd && sleep 5000 ) start second process


I have this script test.sh

#!/bin/bash
( cd . && sleep 5000 )

I execute with ./test.sh & and then run ps lax | grep test.sh

I now have 2 processes running...

0  1000  6883  6600  20   0  10600  1332 -      S    pts/2      0:00 /bin/bash ./test.sh
1  1000  6884  6883  20   0  10604   704 -      S    pts/2      0:00 /bin/bash ./test.sh
  • Why do I have two processes running and where does the second process come from?
  • Why don't I have two processes if I remove the cd ".." from the command?

Thanks for any explanation, I just don't get it and I think I'm lacking some basics here... or is this some vodoo? ;)


Solution

  • Grouping a series of bash commands inside parenthesis will execute them in a sub-shell.