Linux front and back process switching

Source: Internet
Author: User

Linux front and back process switching

When you start a program with the shell, he often works in the foreground. For example, often with putty connection to the remote server to execute the script, if the local network is interrupted, this time the foreground process is over, the comparison of annoyance, must be re-executed. It is therefore necessary to switch between the front and back processes.

For example, to enter Firefox directly in the terminal, it will open Firefox, but when you close this terminal or CTRL + C forced termination, Firefox is also randomly closed. You can add a & after the execution, so it works in the background.

Shell supports function control, with the following commands:

1. Command & let the process run in the background

2. Jobs–l viewing processes running in the background

3. FG%n Let the background run process N to the foreground

4. BG%n let process n Go backstage;

PS: "N" is the process number that jobs looked up.

1. Execute Command & Switch to background

When you run the command at the Linux terminal, add the & symbol at the end of the command to let the program run in the background

[Email protected]$ ./tcpserv01&

2, switch the running program to the background

If the program is running in the foreground, you can use the CTRL + Z option to pause the program and then use the BG%[number] command to run the program in the background, which is divided into 3 steps, as follows:

2.1 Pause program Run CTRL + Z

CTRL + Z is related to the system task, and CTRL + Z can put a command that is executing in the foreground into the background and pauses.

[Email protected] ~]$ sh ins.sh

^z

[1]+ Stopped ins.sh

2.2 Viewing a suspended program

See jobs using the jobs or PS command to see what jobs are executing.

[Email protected] ~]$ jobs-l

[1]+ 4524 Stopped ins.sh

The result of the jobs command execution, + represents a current job, and a minus table is a job after the current job.

The JOBS-L option shows the Pid,jobs status of all tasks can be running, stopped, Terminated

2.3 Switching programs to the background

BG will suspend a command in the background to continue execution if there are multiple commands in the background, you can use BG%jobnumber to bring up the selected command.

[[email protected] ~]$ BG%1

[Email protected] ~]$ jobs-l

[1]+ 4524 Running ins.sh

2.4 Switching programs to the foreground

You can also use the FG%[number] command to drop a program into the foreground to run

[[email protected] ~]$ FG%1

./tcpserv01

2.5 Terminating Daemon

You can also directly terminate a program running in the background, using the KILL command

[[email protected] ~]$ kill%1

However, if the task is terminated (kill), the shell removes the process identity of the task from the list known to the current shell environment, that is, the jobs command displays the task information that is running in the background or suspended in the current shell environment.

Linux front and back process switching (RPM)

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.