Job control instances of Bash and KSH shell in 10 Linux/Unix

Source: Internet
Author: User

Linux and Unix are multi-task operating systems, that is, a system can run multiple tasks (processes) within the same period of time ). In this new blog series, I will list related Linux and Unix job control commands, you can execute multiple tasks in Bash, Korn, and POSIX shell.

What is job control?

Job control is not only able to stop/suspend (stop/suspend) processes being executed (commands), but also can continue/wake (continue/resume) to execute every process you need. This can be done with shell or POSIX shell such as your operating system and bash/ksh.

WHO provides an environment for Job control?

Bash/Korn shell, or POSIX shell, provides the job control environment.

Say hello to the job table.

Your shell will have a form for the current job, called a job table. When you type a command, shell assigns it a jobID (also called JOB)SPEC ). A jobID or JOBSPEC is only a small integer.

#1: Create your first Linux/Unix job

I want to run a command named xeyes, which will display two oval eyes on the screen, enter: $ xeyes &

Output example:

Fig.01: run the xeyes command in the background

I use the & symbol to run a job in the background. Shell prints a line of information similar to the following:

  1. [1] 6891

In this example, two numbers are output, respectively:

  • 1: The Job Number of the xeyes task executed in the background is 1.
  • 6891: process ID of Job 1.

I am executing some more jobs:

  1. # Start a text editor, X system load display, and sleep command ##
  2. Gedit/tmp/hello. c &
  3. Xload &
  4. Sleep 100000 &
#2: List the current job

To view the status of the current shell activation task, enter:

  1. $ Jobs
  2. $ Jobs-l

The output is as follows:

  1. [1] 9379 Running xeyes &
  2. [2] 9380 Running gedit/tmp/hello. c &
  3. [3]-9420 Running xload &
  4. [4] + 9421 Running sleep 100000 &

Brief description:

Field Value Description Example
1 [1] JobID or JOB_SPEC-work number must be used with fg, bg, wait, kill, and other shell commands. You must add a percent sign in the work number Prefix :(%).
Plus sign (+) Identifies the default or current job.
Minus sign (-) Indicates the previous job.
% 1
Fg % 1
Kill % 2
2 9379 Process ID-the unique ID sign that is automatically created and assigned to each process. Killed 9379
3 Running Status-job status:
Running-The job is running and has not been suspended by external signals.
Stopped-The job has been suspended.
N/
4 Xeyes & Command-commands provided by shell. Script &
Firefox url &

You can also use the ps name to list the processes running in the current system:

  1. $ Ps
#3: Stop or suspend a running job

Press the [Ctrl]-[Z] key or use the kill command, as shown below:

  1. Kill-s stop PID

For example, start the ping command and press Ctrl-Z to stop the ping command job:

Animated gif 01: Pending ping command job

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.