KShell background task not showing in jobs
-
22-07-2019 - |
Question
I've written a simple KShell script to kick off a background task
#/bin/ksh
#startMonitoring
./detectFile /usr/local/data/testFile > fileHistory &
I run it with the following command
startMonitoring
When I run jobs I get no results, but the command is running and shows up in ps:
512232 pts/0 0:34 /bin/ksh ./detectFile /usr/local/data/testFile
Why can't I see the item in jobs, and how can I change my script so it does show up in jobs?
Solution
The jobs
command only looks in the current shell. Scripts are run in their own shell. If you source your script instead, then jobs
will show it:
$ . startMonitoring
$ jobs
[1] + Running . startMonitoring
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow