Can someone please show me an example of starting a simple background process on the command line; and then later maybe have to open a new command line and then kill the background process?
closed as off-topic by Milliways, Steve Robillard, joan, Ingo, Ghanima♦ Sep 24 '18 at 11:21
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – Milliways, Steve Robillard, joan, Ingo, Ghanima
You can run a process in the background with the
& at the end. After you started the process, you can get the process number (pid) with
$!. later you can use that process number to kill the process.
sleep 60 & SLEEP_PID=$! sleep 2 kill $SLEEP_PID
If you want to use the pid in another shell, you need to save it to a file.
sleep 3600 echo $! > /tmp/pidfile kill $(cat /tmp/pidfile)