Managing Jobs
Managing Jobs
Managing jobs in a shell involves controlling processes that are running in the background or foreground.
This includes starting, stopping, and resuming jobs.
Key Concepts
Foreground Job: A job that is currently running and interacting with the terminal.
Background Job: A job that is running but does not interact with the terminal. It allows you to
continue using the terminal for other tasks.
Job Control: The ability to manage multiple jobs using various commands.
Common Commands
1. Starting a Background Job: To start a job in the background, append & to the command:
bash
sleep 10 &
2. Listing Jobs: Use the jobs command to list all background and stopped jobs:
bash
jobs
3. Bringing a Job to the Foreground: Use the fg command followed by the job number (found
with jobs):
bash
fg %1
4. Sending a Job to the Background: If a job is running in the foreground and you want to send it
to the background, suspend it with Ctrl + Z, then use:
bash
bg %1
5. Stopping a Job: You can stop a job using the kill command with the job ID:
bash
kill %1
6. Terminating a Job: To forcefully terminate a job, you can use:
bash
kill -9 %1
7. Disowning a Job: To remove a job from the shell's job table, preventing it from receiving a
SIGHUP signal when the shell exits:
bash
disown %1
o Job IDs: Jobs are identified by a unique job ID, which you can see when you run the jobs
command.
o Signals: You can manage jobs using various signals. Common signals include: