I. Process Concept
1. Process andProgramDifference
1) 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, 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, several programs can be executed sequentially in a process activity.
2. Parent and Child Processes
1) A child process is a process generated by a process. The process that generates this child process is called the parent process.
2) in Linux, the fork creation process is called by the system. Fork copies the data and stack segments of the parent process and the process environment of the parent process.
3) The parent process is terminated, and the child process is naturally terminated.
3. foreground and background processes
1) after entering the 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 other commands before it completes.
[Root @ bogon ~] # Find/etc-name init/etc/kdump-AdV-CONF/kdump_initscripts/init/etc/Webmin/init/etc/sysconfig/init [root @ bogon ~] #
2) after entering the command at the shell prompt, if the sub-process created by Shell runs the command, but does not wait for the command to exit, the system returns a prompt to the user. This command is run synchronously with shell, that is, in the background. The background process must be non-interactive.
[Root @ bogon ~] # Find/etc-name init>/tmp/init. Find & [1] 1656 [root @ bogon ~] #
1656 indicates the ID of the sub-process that processes the command.
4. Process status
1) Ready: the process has been allocated resources, but other processes are occupying the CPU, so they cannot run and are waiting for the CPU to be allocated.
2) Waiting: waiting for an event and temporarily unavailable
3) running: the process is allocated to the CPU and is running on the processor.
5. View information of all login users W
[Root @ bogon ~] # W 22:05:30 up 56 min, 2 users, load average: 0.00, 0.00, 0.00 user tty from login @ idle jcpu pcpu whatroot tty1: 31 0.05 s 0.05 s-bashroot pts/0 192.168.0.101 21:11 0.00 s 0.09 s 0.01 s w [root @ bogon ~] #
1) jcpu: it is distinguished by terminal number. The CPU time consumed during execution of all related processes on the terminal is displayed here
2) pcpu: CPU execution time
3) What: the operation being performed by the user
4) Load average: displays the average load of the system in the past 1, 5, and 15 minutes.
5) from: shows where the user logs on
6) idel: user idle time
7) view logon information of individual users: W User Name
6. view the process PS IN THE SYSTEM
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
1) view your own processes
[Root @ bogon ~] # Ps PID tty time cmd 1581 pts/0 00:00:00 bash 1606 pts/0 00:00:00 PS [root @ bogon ~] #
2) view the details of your own processes. PS-U or-l
[Root @ bogon ~] # Ps-uwarning: bad syntax, perhaps a bogu '-'? See/usr/share/doc/procps-3.2.8/faquser PID % CPU % mem vsz RSS tty stat start time commandroot 1473 0.0 0.0 2004 484 tty2 SS +/sbin/mingettyroot 1475 0.0 0.0 2004 480 tty3 SS +/sbin/mingettyroot 1477 0.0 0.0 2004 480 tty4 SS +/sbin/mingettyroot 1479 0.0 0.0 2004 480 tty5 SS +/sbin/mingettyroot 1481 0.0 0.0 2004 508 tty6 SS +/sbin/mingettyroot 1 552 0.0 0.1 8016 1652 tty1 SS +-bashroot 1581 0.0 0.1 6736 1612 pts/0 SS-bashroot 1607 2.0 0.1 6548 pts/0 r + Pm PS-u [root @ bogon ~] #
3) view the information of the specified process in the system
[Root @ bogon ~] # Ps-Le | grep sshd5 S 0 1331 1 0 80 0-2131 -? 00:00:00 sshd4 S 0 1579 1331 0 80 0-2903 -? 00:00:00 sshd [root @ bogon ~] #
[Root @ bogon ~] # Ps-Ef | grep sshdroot 1331 1 0 21:24? 00:00:00/usr/sbin/sshdroot 1579 1331 0? 00:00:00 sshd: root @ pts/0 root 1624 1581 0 00:00:00 pts/0 grep sshd [root @ bogon ~] #
7. Kill-kill the process
1) Close the process: Kill the process number
2) Kill-9 process no. (force close)
3) Kill-l process number (restart process)
4) Close the graphics program xkill
5) killall process name
6) Find the service process number pgrep service name
7) shut down the process: pkill the process name
8. Specify the program running priority
1) Nice specifies the program running priority
Format: Nice-N command
Example: Nice-5 myprogram
2) renice changes the priority of a running process
Format: renice n PID
Example: renice-5 777
3) Priority value range (-20, 19)
9. nohup
The process continues to be executed after the user logs out. The nohup command stores the executed data and error information in the file nohup. Out by default.
Format: nohup Program &
[Root @ bogon ~] # Nohup find/etc-name init *>/root/find. init.20121225 &
10. Process suspension and recovery
1) process suspension (suspension) and termination
Pending: Ctrl + z
Termination: Ctrl + c
2) process recovery
Resume to the foreground and continue running FG
Resume running BG in the background
3) view the suspended process jobs
[Root @ bogon ~] # Jobs [1] + stopped find/-name inittab [root @ bogon ~] #
Transferred to the front-end for execution: FG number
[Root @ bogon ~] # FG 1 find/-name inittab/etc/Webmin/inittab/etc/inittab/backup/etc/inittab
Execute the BG number in the background.
[Root @ bogon ~] # BG 1
11. Top
Process status display and process control, automatically refreshed every 5 seconds (Dynamic Display)
Common options: (used after top execution)
D: Specifies the interval of refreshing.
C: display a real command line, not just the command name
U: View processes of a specified user
K: Terminate the process in progress.
H or? : Get help
R: reset the process priority.
W: Write the current settings ~ /. Toprc File
Ii. Schedule Tasks
1. Task Scheduling command
1) At arranges a job to be executed once at a certain time.
Schedule one or more commands to run at a specified time
At Command Format and parameters:
At [-F file name] Time
The at command specifies the time:
Absolute timing method:
Midnight noon teatime
Hh: Mm [Today]
Hh: mm: tomorrow
Hh: Mm week
Hh: Mm mm/DD/yy
Relative timing method:
Now + n minutes
Now + N hours
Now + N days
Specify to execute a command at this afternoon. Assume that the current time is, January 1, January 2, 2013.
The command format is as follows:
At 6: 00 pm
At 18:00
At 18:00 today
At now + 3 hours
At now + 180 minutes
At 18:00 2.1.13
At 1/2/13
Interactive execution: for example, broadcast the content in/etc/motd in 5 minutes.
[Root @ localhost ~]#At now + 5 minutesAt>/usr/bin/wall </etc/Motdat> <EOT>Job1[Root@ Localhost ~]#
After entering the command, press Ctrl + D to save it. Once the time arrives, the content will be broadcast.
Use command file
Write the command to be executed in the script file at. script, and then use the following command
[Root @ localhost ~]#At-f at. Script 1/2/13Job 2[Root@ Localhost ~]#
At-l or ATQ: View tasks in the queue
[Root @ localhost ~]#At-l2A root [root@ Localhost ~]#
[Root @ localhost ~]#ATQ2A root [root@ Localhost ~]#
At-D or atrm delete a task in the queue
[Root @ localhost ~]#At-D 2[Root @ localhost ~]#
The generated scheduled tasks are stored in:/var/spool/.
At configuration file
Purpose: restrict which users can use the AT command
/Etc/at. allow
/Etc/at. deny
2) The batch job is executed once when the system load is not heavy.
Schedule one or more commands to be executed once when the system load is light (generally, the load is light, that is, the average load is reduced to less than 0.8)
The usage is the same as
3) scheduled periodic jobs by Cron
Used to generate the crontab file required by the cron Process
Crontab command format
Crontab {-L |-r |-e}
-L display the current crontab
-R: Delete the current crontab.
-E use the editor to edit the current crontab file.
Crontab file format:
Minute hour day month week command/script
Minute hour day-of-month-of-year Day-of-week commands
Minute In an hour [0 ~ 59]
Hour in a day in hour [0 ~ 23]
Day-of-month in April January [1 ~ 31]
Month-of-year in which month [1 ~ 12]
Day-of-week which day of the week [0 ~ 6]
Command executed by commands
Minute hour day month week command/script
Execute at every morning: 0 4 ***
Run at six o'clock P.M. on Tuesday and Friday: 0 18 ** (separated by commas)
Run the following command from April 1st to April 2nd and Friday six o'clock P.M.: 0 18*1-3, 5 (continuous values are connected)
*/2 (every 2 minutes)
After the crontab file is created, you can go to the/var/spool/cron directory to confirm