Managing Shell jobs
Job Management in Unix/Linux Shell
Introduction
Users have the ability to manage their own jobs in the Unix/Linux shell. This includes starting, stopping, and moving jobs between foreground and background.
Starting a Job in the Background
To start a command as a job in the background, append an ampersand (&) at the end of the command.
Example:
Command:
sleep infinity &This will run the command 'sleep' indefinitely as a background job.
Moving a Running Job to the Background
If a job is currently running in the foreground, you can temporarily stop it by using the keyboard shortcut:
Control + Z
To move the stopped job to the background, use the command:
bgThis command will resume the job in the background after it has been stopped.
Overview of Running Jobs
The command
jobsprovides a complete overview of all currently running jobs, including their job numbers and statuses.
Moving a Job to the Foreground
To move a job from the background back to the foreground, use the command:
fg[job number]This command brings the specified job back to the foreground where it can be interacted with directly.
Examples
Example of running a command:
Initial Command:
sleep infinityResult: Runs as a foreground job.
To manipulate this job:
Stop the job: Control + Z
Move to background:
bg
Result: The job continues to run in the background.
Terminating a Job
To terminate a job currently running in the foreground, use the keyboard shortcut:
Control + C
This command sends an interrupt signal to the job, terminating it.
Conclusion
The management of jobs in the Unix/Linux shell is a straightforward process involving stopping, starting, and manipulating jobs between foreground and background using simple commands and keyboard shortcuts.
Users can effectively manage their shell environment by utilizing the commands
bg,fg,jobs, and control signals like Control + Z and Control + C.