Last active
March 25, 2020 20:31
-
-
Save estysdesu/8b9afdf447ac4c0424e1f1010ecee1eb to your computer and use it in GitHub Desktop.
[Shell: Foreground <--> Background] #sh #fg #bg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://askubuntu.com/questions/8653/how-to-keep-processes-running-after-ending-ssh-session -- nohup, disown | |
##### `&` (BACKGROUND) ##### | |
# foreground task (blocking) | |
ping localhost > /dev/null | |
# background task (non-blocking) | |
ping localhost > /dev/null & # returns [<jobNo>] <PID> | |
##### `jobs` (SHOW RUNNING BG JOBS) ##### | |
ping localhost > /dev/null & # --> [1] 107 | |
ping localhost > /dev/null & # --> [2] 128 | |
jobs # --> [1] & [2] details | |
##### `fg`/`bg` (SWAP FG/BG FOR A RUNNING JOB) ##### | |
fg %1 # brings [1] to the fg --> `ping localhost > /dev/null` | |
bg %1 # sends [1] to the bf --> `ping localhost > /dev/null &` | |
##### PAUSE/SUSPEND JOB (<Ctrl+Z>) ##### | |
# regain control of the terminal by suspending a job by pressing <Ctrl+Z> while it has the fg | |
fg %1 | |
<Ctrl+Z> # --> [1] Stopped | |
bg %1 | |
##### `kill`/`killall`/`pkill` (KILL[ALL] JOB) ##### | |
ping localhost > /dev/null & # --> [3] 110 | |
kill %3 # --> [3] Terminated | |
killall ping # kills [1] and [2] | |
sleep 88888 & # --> [4] 148 | |
pkill -15 sleep # kill with SIGTERM (15) (SIGKILL is 9) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment