0% found this document useful (0 votes)
65 views2 pages

Whats A Job in Linux: $ Sleep 100 & (1) 1302 $

A job in Linux is a process managed by the shell. There are three types of jobs: foreground jobs which occupy the terminal until complete, background jobs which run without occupying the terminal using an ampersand, and stopped jobs which can be suspended using Ctrl-Z. The shell assigns each job an ID and PID for management. Background jobs can be listed and manipulated using job control commands like jobs, fg to bring to foreground, and bg to run in background. The directory stack maintains a list of recently visited directories that can be manipulated using pushd to add and popd to remove, with dirs displaying the contents.

Uploaded by

Viraj Bhosale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views2 pages

Whats A Job in Linux: $ Sleep 100 & (1) 1302 $

A job in Linux is a process managed by the shell. There are three types of jobs: foreground jobs which occupy the terminal until complete, background jobs which run without occupying the terminal using an ampersand, and stopped jobs which can be suspended using Ctrl-Z. The shell assigns each job an ID and PID for management. Background jobs can be listed and manipulated using job control commands like jobs, fg to bring to foreground, and bg to run in background. The directory stack maintains a list of recently visited directories that can be manipulated using pushd to add and popd to remove, with dirs displaying the contents.

Uploaded by

Viraj Bhosale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Whats a job in Linux

A job is a process that the shell manages. Each job is assigned a sequential job ID.
Because a job is a process, each job has an associated PID. There are three types of
job statuses:
1. Foreground: When you enter a command in a terminal window, the command
occupies that terminal window until it completes. This is a foreground job.
2. Background: When you enter an ampersand (&) symbol at the end of a
command line, the command runs without occupying the terminal window. The
shell prompt is displayed immediately after you press Return. This is an example of
a background job.

Running a Job in the Background


To run a job in the background, you need to enter the command that you want to
run, followed by an ampersand (&) symbol at the end of the command line. For
example, run the sleep command in the background.

$ sleep 100 &


[1] 1302
$

The shell returns the job ID, in brackets, that it assigns to the command and the
associated PID. With the job ID, you can use the job control commands to manage
the job whereas the kernel uses PIDs to manage jobs.

When a background job is complete and you press Return, the shell displays a
message indicating the job is done.

[1] + Done sleep 100 &


$

Managing the background jobs


You can use the jobs command to list the jobs that are currently running or
suspended in the background.

$ jobs
[1]+ Running sleep 100 &

You can use the fg command to bring a background job to the foreground.

$ fg % 1
sleep 100

Note: The foreground job occupies the shell until the job is completed, suspended,
or stopped and placed into the background.

You can use the ‘Control+Z keys and bg command to return a job to the


background. The Control+Z keys suspend the job, and place it in the background as
a stopped job. The bg command runs the job in the background. For example:
1. Using CTRL+Z

$ sleep 100
^Z
[1]+ Stopped sleep 100
$ jobs
[1]+ Stopped sleep 100

2. Using bg

$ bg % 1
[1]+ sleep 100 &
$ jobs
[1]+ Running sleep 100 &

Directory stack manipulation

 The Directory Stack

• Directory Stack Bash builtin commands to manipulate the directory stack.


  
Builtins:
The directory stack is a list of recently-visited directories. The pushd builtin adds directories
to the stack as it changes the current directory, and the popd builtin removes specified
directories from the stack and changes the current directory to the directory removed.
The dirs builtin displays the contents of the directory stack. The current directory is always
the "top" of the directory stack.
The contents of the directory stack are also visible as the value of the DIRSTACK shell
variable.

You might also like