Search code examples
node.jsbashshellprocessdetach

How to list processes detached in a script?


I have:

$ cat ./test
#!/bin/bash

gulp dev &

Then run it:

$ ./test
...

(.. hit enter to get command prompt) The command in the script starts node process. But I haven't it among background processes:

$ jobs -p

prints empty list. So the aim is to be able to list/kill (multiple) processes started and detached inside a single script. How to?


Solution

  • Your interactive shell only manages the jobs that it started. When you run a script as a command, the background processes are started by the subshell, not the original shell.

    You need to source the script, so that it will be run by your interactive shell:

    source ./test