RHEL6 System Process Management-Task Management

Source: Internet
Author: User
1. First, let's take a simple look at the concepts related to programs and processes: some binary files for users. Process: Some information related to the program that is loaded into the memory after the program runs. Such as process id pid and memory usage. A program is a static concept. As a software resource, a process is a program execution process. It is a dynamic concept and has a certain life cycle. It is generated and extinct dynamically. There is no one-to-one correspondence between programs and processes. A program can be shared by multiple processes. On the other hand, a process can execute several programs sequentially in the activity. Parent

1. Let's take a simple look at the concepts related to programs and processes.
Program: binary files used by users.
Process: Some information related to the program that is loaded into the memory after the program runs. Such as process id pid and memory usage.
A program is a static concept. As a software resource, a process is a program execution process. It is a dynamic concept and has a certain life cycle. It is generated and extinct dynamically.
There is no one-to-one correspondence between programs and processes. A program can be shared by multiple processes. On the other hand, a process can execute several programs sequentially in the activity.

Parent process: the first process when the program runs can be understood as the parent process.
Sub-Process: A process derived from a program process is called a sub-process.
When the parent process is terminated, the child process also terminates. But the child process is terminated, and the parent process is not necessarily terminated.

2. Task Management
Work Management is the behavior management of multiple jobs simultaneously under a single terminal interface in the Bash environment. For example, after logging on to Bash, you need to compile software, copy files, edit files, and so on at the same time. This requires job management. Of course, you can also open several more terminals to do the above work at the same time. However, after all, the terminal is sometimes used up, or the number of use or connections is limited, it is possible that only one terminal can be opened to work for you.

Here we also need to know what the foreground and background processes are.
Foreground: for example, after entering a command at the shell prompt, create a sub-process, run the command, and shell waits for the command to exit, and then returns to give a prompt to the user. This command is run asynchronously with shell, that is, on the foreground. You cannot execute another command before it is completed.

Background: for example, after entering a command at a shell prompt, if a sub-process created by shell is followed by an &, run this command without waiting for the command to exit, and directly return a prompt to the user. This command is run in sync with shell, that is, in the background. However, the background process must be non-interactive. Then, the background process cannot be terminated using Ctrl + c.

Related commands
Run the command in the background, that is, add "&" to the end of the command.

Process Suspension and Termination
Pause: Ctrl + z
Termination: Ctrl + c

Process recovery
Resume to the foreground and continue running: fg
Resume to the background and continue running: bg

View background processes: jobs

The following is an example.

[Root @ www.linuxidc.com ~] # Cp-r/usr // tmp &
[1] 1627 the copied command is put in the background for operation. Its PID is 1627, and the task number is 1.

[Root @ www.linuxidc.com ~] # Jobs
[1] + Running cp-I-r/usr // tmp & check that the command is Running

If you set the command to the foreground, use the following command:

[Root @ www.linuxidc.com ~] # Fg % 1
Cp-I-r/usr // tmp use Ctrl + z to throw the command to the background and pause it

^ Z
[1] + Stopped cp-I-r/usr // tmp view task status

[Root @ www.linuxidc.com ~] # Jobs
[1] + Stopped cp-I-r/usr // tmp to continue working

[Root @ www.linuxidc.com ~] # Bg % 1
[1] + cp-I-r/usr // tmp & we can see that the task continues.

[Root @ www.linuxidc.com ~] # Jobs
[1] + Running cp-I-r/usr // tmp & if jobs are used for viewing after the task is executed, a Done prompt is displayed.

[Root @ www.linuxidc.com ~] # Jobs
[1] + Done cp-I-r/usr // tmp Note: even if the program is executed in the background, if your terminal is disconnected, programs executed in the background will also be interrupted. The following methods can be used to solve this problem.
1. implement it with scheduled tasks (this is not much to say, because it is common)
2. Use nohup: nohup [commands and parameters] &

[Root @ www.linuxidc.com ~] # Nohup cp-r/usr // tmp &
[1] 1699
[Root @ www.linuxidc.com ~] # Nohup: ignoring input and appending output to 'nohup. out'

[Root @ www.linuxidc.com ~] # Jobs
[1] + Running nohup cp-r/usr // tmp &
[Root @ www.linuxidc.com ~] # Exit and log on again

[Root @ www.linuxidc.com ~] # Jobs won't be able to see anything at this time, but they can be found in ps.

Ps-ef | grep cp
Root 1699 1 10? At 00:00:06, the process ID cp-r/usr // tmp is still 1699, which is the same as the above. This means that even though the terminal exits, the task is not interrupted and continues to be executed.

Related Article

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.