0

I want to list the background processes in the script, and after entering the PID the process ends.

#!/bin/bash
jobs -l
echo "Inter PID process: "
read var_PID
kill $var_PID

I tried this "jobs -l"

and that "sudo jobs -l"

Displays immediately without processes:

"Inter PID process: "

danilfg
  • 11
  • 2
  • There are no background processes in this script, so the output is empty. What did you expect? – KamilCuk Jun 17 '19 at 13:36
  • I wanted to see the processes first and then I had to enter PID. Doesn't entering background processes show _jobs -l_ as you type? When I enter in terminal _jobs -l_, they are shown. – danilfg Jun 17 '19 at 13:38
  • Your running terminal may have some background jobs. The script does not. Jobs are not inherited by scripts. You can `source ./your_script` to source the script instead of running it as a separate process. – KamilCuk Jun 17 '19 at 13:42
  • So it works, thanks! Is it possible to run without _source_? – danilfg Jun 17 '19 at 13:46
  • Possible duplicate of [Why can't I use job control in a bash script?](https://stackoverflow.com/questions/690266/why-cant-i-use-job-control-in-a-bash-script) – KamilCuk Jun 17 '19 at 13:54

0 Answers0