Linux Process Management

Source: Internet
Author: User

Linux Process Management
|-Process Concept
|-Process Management Commands
|-Scheduled Tasks

I. Differences in processes and procedures
1, the program is a static concept, itself as a software resource for long-term maintenance, and process is the process of execution, it is a dynamic concept,
There is a certain period of life, is the dynamic production and extinction.
2. There is no correspondence between procedures and processes. A program can be shared by multiple processes, and on the other hand, a process has
Sequential execution of several programs

foreground process and background process
Foreground process:
After hitting the command at the shell prompt, create a child process, run the command, the shell waits for the command to exit, and then return to the prompt for the user. This command is in line with the shell
Runs asynchronously, which is run in the foreground, and the user cannot execute another command until it is complete
Background process:
Hit the command at the shell prompt, and if you run this command with a child process created with a &,shell, but do not wait for the command to exit, return directly to the user's prompt. This command
Runs synchronously with the shell, which runs in the background. Background processes must be non-interactive.

View user Information W
W Displays the meaning of the message
JCPU: The terminal code is used to differentiate the CPU time that is consumed when all relevant processes of the terminal are executed.
PCUP:CPU time spent executing the program
What: Actions the user is performing
View individual user information: W User name
Load average: Shows the average load level of the system in the last 1, 5, 15 minutes, respectively
From: Shows the user from where to log on to the system, ": 0" display on behalf of the user is from the X window, open Text mode window login
Idle: The user is idle time. This is a timer that will be reset once the user performs any action

Ii. process Commands
PS Common Options
A: Show processes for all users
U: Display user name and start time
...

PS Application Example
# PS View the process that belongs to you
# ps-u Or-l View the details of your own process
# Ps-le Or-aux View details of processes performed by all users
# Ps-aux--sort pid can sort processes by process execution time, PID, UID
# Ps-aux | grep Sam
# Ps-uu Sam View the process specified by the user in the system
# Ps-le | grep init view specified process information
# Pstree | More

Kill-Kill Process
Shutdown process: Kill process Number
Kill-9 process number (forcibly closed)
KILL-1 process Number (restart process)
Close graphics Program: Xkill
End All Processes: Killall
Lookup service Process number: Pgrep Service Name
Shutdown process: Pkill process Name

Nice and Renice
Nice
To specify a program's run priority
Format: nice-n
Example: # nice--5/etc/rc.d/init.d/httpd start
Renice
Change the priority of a running process
Format: renice N pid
Example: Renice-5 777
The priority value range is ( -20,19)

Nohup
Causes the process to continue execution after the user exits the login, and the nohup command stores the executed data information and error information by default to
In File Nohup.out
Format: Nohup Program &
# nohup Find/-name init* >/root/find.init.20151125 &

Process suspend and resume
Abort (hang) and terminate of process
Hang Ctrl +z
Stop Ctrl + C
Recovery of the process
Revert to foreground to continue running FG
Revert to background to continue running BG
View suspended processes Jobs

Top
Function: Process status display and process control, automatically refresh once every 5 seconds (dynamic display)
Common options:
D: Specify the time interval for refresh
C: Display the entire command line instead of displaying the command name
Common commands:
U: View the process for a specified user
K: Terminate the process in progress
H or? : Get Help
R: Re-set process priority
S: Change the time interval for refresh
W: Writes the current settings to the ~/.TOPRC file

Iii. Scheduled Tasks
commands for scheduling tasks
At scheduling a job to execute at a time
Batch schedules jobs to execute once when the system load is not heavy
Cron scheduling jobs that run periodically

Functions and formats of the ※at command
Function: Schedule one or more commands to run once at a specified time
command format and parameters for at
at [-F filename] Time
at-d or ATRM Delete a task in a queue
At-l or ATQ view tasks in a queue

Absolute Timing Method
Midnight Noon Teatime
Hh:mm[today]
HH:MM tomorrow
HH:MM Week
hh:mm mm/dd/yy DD. Mm. Yy
Relative Timing method
Now + N minutes
Now + N Hours
Now + N Days

Usage examples:
Interactive mode at 9:00
Using command file Mode
1. Generate File At.script
2. Using the AT command
At-f At.script 9:00 2/2/11
Or
At < At.script 9:00 2/2/11
[Email protected] ~]# at now +100 minutes
At>/usr/bin/wall </etc/motd<eot>

At configuration file
Role: Restrict which users can use the AT command
/etc/at.allow/etc/at.deny

※batch command
Function: Schedule one or more commands to run once when the system load is low (under normal load the lighter average load drops below 0.8)
Use method same as at

※crontab command format
Role: Crontab files required for the production of cron processes
Crontab's command format
crontab{-L |-r |-e}
-L Displays the current crontab
-R Delete Current crontab
-e Use the editor to edit the current crontab file.
Minute hour day-of-month month-of-year day-of-week commands
Crontab-e
Minutes Hours Day Month Week command/script
0 4 * * *
0 18 * * 2,5
0 18 * 1-3 2,5
* * 1-5/usr/bin/wall </etc/issue
* * 1-5/sbin/shutdown-h now
*/2 (every) 12-14 * 3-6,9-12 1-5/bin/cp-r/etc/backup/etc.20151111 2>/backup/etc.bak.err
Writing main items:
None of these items can be empty and must be filled in
You do not need to specify several items with * to indicate any time
Specify multiple values with a comma interval
The command should give the absolute path
The user must have permission to run the corresponding command or program

Crontab file can be confirmed to/var/spool/cron directory after it is established.
Crontab configuration file/etc/crontab
Restrict which users can use
/etc/cron.allow/etc/cron.deny

Process processing Mode
Standalone standalone operation
XINETD Process Hosting
ATD, Crond Scheduled Tasks

Linux Process Management

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.