Jobs Command:
jobs: Jobs command is used to list the jobs that you are
running in the background and in the foreground. If the prompt is returned with
no information no jobs are present. All shells are not capable of running this
command. This command is only available in the csh, bash, tcsh, and ksh shells.
Options:
-l Provides
more information about each job listed. This information includes the job
number, current job, process group ID, state, and the command that initiated
the job.
-n Display
only jobs that have stopped or exited since last notified-r Display running jobs
-s Display stopped jobs
$ jobs
[1]- Stopped mail[2] Running fi.sh &
[3]+ Stopped sleep 200
First field (job-number):
Indicates the process group number to use with the wait, fg, bg, and kill commands. When used with these commands, prefix the job number with a % (percent sign).Second Field (Current Field):
A - (minus sign) tells that the job becomes the default if
the current default job exits. This job ID can also be specified using %-
(percent sign, minus).
For other jobs, the current field is a space character. Only
one job can be identified with a +, and only one job can be identified with a
-.Third Field (State of job):
It can be running, stopped, done etc
bg Command:
bg : Runs jobs in the background. bg command resumes
suspended jobs in the current environment by running them as background jobs.
If the specified job is already running in the background, the bg command has
no effect and exits successfully. If no JobID parameter is supplied, the bg
command uses the most recently suspended job as below.
$ bg
If more jobs are running we can use job no to send specific
job in background as below.
$ bg 2
A job can be suspended using ctrl+z key
sequence. That job can be restarted in the background using the bg command.
Example:
Start a job in foreground
$ sleep 120
Press Ctrl+z to stop the current job.
Now move the last stopped job to background.
$ bg
If the output of the jobs command displays
the following stopped job:
$ bg %2
Example:
$ sleep 120 &
fg Command:
fg : Runs jobs in the foreground. the fg command
moves a background job in the current environment into the foreground. Use the job ID parameter
to indicate a specific job to be run in the foreground. If this parameter is
not supplied, the fg command
uses the job most recently suspended, placed in the background, or run as a
background job as below.
$ fg
Specifying the job id will resume that particular job as
below.
$ fg 2
Linux Processes batch and at commands in Linux
No comments:
Post a Comment