Linux Background Commands: Using &, jobs, bg, and fg
HardReset.InfoDecember 16, 20254 min38 views
5 connectionsΒ·10 entities in this videoβRunning Commands in the Background
- π‘ To run a command in the background on Linux, append an ampersand (&) to the command.
- π For example,
sleep 1000 &will run thesleepcommand for 1000 seconds in the background, and you will receive the Process ID (PID).
Managing Background Jobs
- π The
jobscommand is used to list all processes currently running in the background. - βΈοΈ A foreground process can be suspended by pressing Ctrl+Z.
- β Pressing Ctrl+C will stop a foreground process entirely.
Moving Processes Between Foreground and Background
- π€ To move a stopped job to the background, use the
bgcommand followed by the job number (e.g.,bg %2). - π₯ To bring a background job back to the foreground, use the
fgcommand followed by the job number (e.g.,fg %1).
Use Cases and Alternatives
- β±οΈ Running commands in the background is particularly useful for long-running scripts or algorithms that take several minutes to complete, preventing the terminal from being occupied.
- π For persistent background jobs that should continue even after the terminal is closed, consider alternatives like
nohup,disown,screen, ortmux.
Knowledge graph10 entities Β· 5 connections
How they connect
An interactive map of every person, idea, and reference from this conversation. Hover to trace connections, click to explore.
Hover Β· drag to explore
10 entities
Chapters2 moments
Key Moments
Transcript16 segments
Full Transcript
Topics14 themes
Whatβs Discussed
LinuxBackground ProcessesTerminal CommandsAmpersand (&)jobs commandbg commandfg commandProcess ID (PID)Ctrl+ZCtrl+Cnohupdisownscreentmux
Smart Objects10 Β· 5 links
ProductsΒ· 3
ConceptsΒ· 7