Linux Study Notes-Process Management

Source: Internet
Author: User

Linux Process Management
1. A program is a static concept. It is stored as a software resource for a long time. A process is the execution process of a program. It is a dynamic concept and has a certain life cycle, is dynamically generated and extinct.
2. There is no one-to-one correspondence between a program and a process. A program can be shared by multiple processes. On the other hand, a process can execute several tasks sequentially in the activity.
Parent and Child Processes
1. A child process is a process generated by a process. The process that generates this process is called the parent process.
2. in Linux, use the system to call fork to create a process. Fork copies the data and stack of the parent process and the termination environment of the parent process.
3. The parent process stops the child process and ends naturally.
Foreground and background processes
Foreground Process
After the shell prompts a command, create a sub-process, run the command, and wait for the shell command to exit, and then return 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 Process
Run the command in the shell prompt. If a subprocess created by the shell is subsequently entered to run the command, but does not wait for the command to exit, the subprocess is directly returned to give a prompt to the user. This command is run in sync with shell, that is, in the background. The background process must be non-interactive.

Process status (related to the time-sharing concept of the operating system)
1. Ready: the process has been allocated resources, but because other processes are occupying the CPU, it cannot run and is waiting for the CPU to be allocated.
2. Waiting: waiting for an event and temporarily unavailable
2. Running: the process is allocated to the CPU and is running on the processor.

Process status refinement
User Execution Mode: Execute user code on the CPU
Core running state: execute core code on the CPU
In-memory ready: Has running conditions, only wait for the scheduler to allocate CPU for it
In-memory sleep: waiting in the memory for a certain event
In the external store ready: The ready process is switched to the external store and continues to be in the ready state.
Out-of-memory sleep: The sleep process is switched to the out-of-memory to continue waiting
Pause in memory: The Stop program is called and the tracing is paused. Wait for the parent process to send the command.
Paused on External Storage: Processes in the paused state are switched to external storage.
Creation state: the intermediate state in which the new process is being created but not completed
Terminating state: the process terminates itself.

Common commands
W display meaning
Jcpu is the total CPU usage time, And pcpu is the time used to execute an operation.
What indicates what the user is doing
Load average refers to the average load in the past 1, 5, 15 minutes, less than 0.8 of the load is considered to be light
From shows where the user logs in. 0 indicates that the user logs in through the terminal in X Window.
Idle indicates the user's idle time. Once the user performs any operation, the data will be updated.

PS Process status
Common options
A: displays the processes of all users.
U: displays the user name and start time
X: displays the processes without control terminals.
E: displays all processes, including those without control terminals.
L: long format display
W: Wide Row display. You can use multiple W for wide display.

[Root @ Lovelock ~] # Ps-l
F s uid PID ppid C pri Ni addr sz wchan tty time cmd
4 S 0 1907 1903 0 80 0-27073 wait pts/0 00:00:00 bash
4 R 0 1929 1907 0 80 0-27031-pts/0 00:00:00 PS
PID process number, ppid parent process number, tty process start terminal,
Current state of the stat process: s sleep state, d Non-interrupted sleep state, r running state, Z dead state, t stopped state
Ni process priority
Time total CPU usage since the process is started
Command name of the CMD Process
User
% Percentage of CPU usage time and total time
% Mem memory usage and percentage of total system memory

PS-Le or-Aux: view detailed information about processes executed by all users
Why should we kill the process?
This process occupies too much CPU time
The process locks a terminal and prevents other foreground programs from running.
It took a long time to run and failed to achieve the expected results.
Excessive output to screen or disk files is generated
Unable to exit normally

Kill process Shutdown
Kill-9 process no. Is forcibly disabled
Kill-1 process number restart process
Close the graphics program xkill
Killall httpd
Find the service process number pgrep service name
Shut down the pkil process name
/Proc files are stored in the memory image, not in the hard disk.

Nice and renice
Nice
Specifies the priority of the program running
Nice-N command
For example, nice-5 myprogram
Renice
Change the priority of a running process
Format: renice n PID
For example, renice-5 777
Value range of priority (-20 ~ 19)

Nohup allows the process to continue execution after the user launches the login
Process suspension and recovery
Hold Ctrl + z
Terminate Ctrl + c
Process recovery
Resume to the foreground to continue (FG)
Resume to the background for execution (BG)
View suspended processes (jobs)

Top Process status display and process control, automatically refreshed every five seconds (Dynamic Display)
D. Specify the interval of refreshing.
C. display the entire command line, not just the command name.
U view processes of a specified user
K. Stop the process in progress.
H or? Get help
R. Reset the process priority.
S changes the interval of refreshing
W write the current settings ~ /. Toprc File

Scheduled tasks
At arranges a job to be executed at a certain time.
At command functions and formats
At [-F file name] Time
At-D or atrm delete a task in the queue
At-l or ATQ: View tasks in the queue
Note that the absolute path must be written for the command.
Restrict the use of at files
/Etc/at. allow
/Etc/at. deny
If both files do not exist, only the root user can use the AT command.

The batch job is scheduled to run once when the system load is not heavy.
Is the sub-command of
Generally, when the load is lighter, the average load is reduced to less than 0.8.

Jobs scheduled by Cron
Crontab
-E Edit
Format
Minutes, hours, and days
Months and weeks
Command/script
0 4 *
**

Add the specific time you know, and fill in all the time you don't know *
A temporary file is generated when the scheduled task is executed and deleted after completion.
Process Processing Method
Standalone has been running requests waiting for listening ports in the system since it was started independently. Once there is a request, the system will immediately respond and consume a large amount of system resources. Therefore, WebServer is usually standalone with a high speed.
Xinetd processes host super Internet Daemon Processes and listen to intermediate processes
Scheduled tasks of ATD and crond

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.