KandZ – Tuts

We like to help…!

Linux CLI 22 🐧 background/foreground processes and system reboot/shutdown

You can control whether a background runs in the background or in the foreground
& symbol at the end of the command starts the command in the background
example 1 → it lists the files and displays job id [1] and the PID of the background task
example 2 → set the command to the background without showing the file
nohup → stands for no hang up, lets the command run after you close the terminal
example 1 → runs the ls command and prevents it from being terminated
example 2 → displays the commands that have been save to nohup.out
nohup bash -c 'cmd1 && cmd2' → redirects the output to nohup.out from multiple commands
use cat nohup.out to see the result of the execution

jobs → lists all jobs with their numbers.
it helps identify which job you need to bring to foreground
-s → shows only stopped jobs, -r → show only running jobs, p → shows only the PID
fg → brings the previous background process to the foreground
fg %JN → brings a specific background process to the foreground
some distros do not need the %
example 1 → kills the job with the current number

sudo shutdown -h now → Immediately shut down the system after confirmation
sudo shutdown -h +n → Shut down the system in n minutes
sudo shutdown -h 0 → Shut down the system immediately
sudo reboot → Immediately reboot the system after confirmation
sudo reboot -t n → Reboot the system in n minutes
sudo reboot 0 → Reboot the system immediately
sudo poweroff → Immediately power off the system after confirmation

Leave a Reply