The parent process terminates the child process naturally.foreground process and background process
Foreground process:
After the command is entered at the shell prompt, a child process is created to run a
Order, the shell waits for the command to exit and then returns to the user's prompt
Character. This command runs asynchronously with the shell, which is run in the foreground and the user
It cannot execute another command until it is complete.
Background process:
The command is entered at the shell prompt, and if a child is created with a &,shell
The process runs this command, but does not wait for the command to exit and returns directly to the
The user gives a hint. This command runs synchronously with the shell, which is shipped in the background
Yes. Background processes must be non-interactive.
Example: # Find/-name init >/test/init.find &
Process status
Ready: The process has been divided
Resources, but because
Other processes are occupying
CPU, so temporarily not
Can run and wait for distribution
The state of the CPU.
?
Wait for some kind of
Events and temporarily unable to ship
The state of the row.
?
Run: Process assigned to
CPU, processor in progress
Run on.
Process State Refinement
User-state operation: Executing user code on the CPU
?
Kernel mentality run: Execute core code on CPU
?
In memory-ready: With running conditions, just wait for the scheduler to allocate CPU for it
?
In-memory sleep: Waiting for an event to occur while waiting in memory
?
In external memory ready: Ready process is swapped to external memory to continue in ready state
?
In external memory sleep: The sleep process is swapped to external memory to continue waiting
?
Pause in Memory: The Stop program is called to enter the trace pause state, waiting for its
The parent process sends the command.
?
Pause on external memory: process in track suspended state is swapped to external memory
?
Create state: An intermediate state in which a new process is being created, but not yet completed
?
Termination state: Process terminates itself
View user Information W
? W Displays the meaning of the message
? JCPU: The terminal code to distinguish, the terminal all phase
CPU time that is consumed when the process is executed.
? PCPU: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 where the user logs on to the system, ": 0"
displayed on behalf of the user from the X window, open the text
This mode window is logged in
? Idle: The user is idle time. This is a timing
Once the user performs any action, the timer is reset
View the process PS in the system
Common options
? A: Show processes for all users
? U: Display user name and start time
? x: Show process without control terminal
? E: Show all processes, including those without control terminal
? L: Long format display
? W: Wide line display, can be used to widen the display with multiple W
The meaning of common output information of PS
? PID: Process Number
? PPID: Process number of the parent process
? TTY: Process-initiated terminal
? STAT: The current state of the process
S sleep state, d non-interruptible sleep state, R run
Status, Z Zombie State, T stop
? NI: Process Priority
? Time: Total CPU times that the process has been enabled since it was started
? Command/cmd: The command name of the process
? User: Username
? %cpu: Percentage of CPU time and total time consumed
? %MEM: Percentage of total memory consumed and system memory
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 be executed by process time,
PID, UID, etc to sort the process
# Ps-aux | grep Sam
# Ps-uu Sam//view SAM user-executed processes
To view the processes performed by a specified user in the system
# Ps-le | grep init view specified process information
Pstree | More View process Tree
kill– Kill Process
Why to kill a process
? The process is consuming excessive CPU time
? The process has shrunk a terminal so that no other foreground process can run
? Running too long, but with no expected effect
? Produce too much output to screen or disk files
? Unable to exit normally
kill– closing 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//# killall httpd close httpd All processes
? find service Process number: Pgrep service name//# pgrep httpd
? Close process: Pkill process name//# pkill httpd
Nice and Renice
? Nice
? To specify a program's run priority
? Format: Nice-n command
Example: Nice-5 myprogram//# 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//Ps-le | grep httpd View httpd process
* Priority value range is ( -20,19) *
Nohup
The process continues after the user exits the login
Line, the Nohup command will execute the data after the information and
Error messages are saved to file nohup.out by default
Format: Nohup Program &
Case: # Nobup Find/-name init* >/root/find.init.20110106 &
Process suspend and resume
? Abort (hang) and terminate of process
? Hang up (ctrl + Z)
? Terminate (CTRL + C)
? Recovery of the process
? Revert to foreground to continue running (FG)
? Restore to background 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
Scheduled Tasks
? Why do I need to set up 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
function and format of AT command
Function: Schedule one or more commands at a specified time
Run Once
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 scheduled tasks in the queue
How 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
? Specifies that a command is executed at 17:30 today (assuming the current time is 14:30, January 11, 2011).
? The command format is as follows:?
At 5:30pm
At 17:30?
At 17:30 today?
At now + 3 hours?
At now + minutes?
At 17:30 11.1.11?
At 17:30 1/11/11
Example of using at command
? 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
At configuration file
Role: Restrict which users can use the AT command
? /etc/at.allow
? /etc/at.deny
Execution results and configuration files for at
If the/etc/at.allow file exists, then only columns are listed here
The user in the file can use the AT command;
/etc/at.allow file does not exist, check/etc/at.deny
Whether the file exists. If/etc/at.deny exists, then this
Users listed in the file cannot use the AT command. If
None of the two files exist, only the super user can
Use the AT command. If all two files are present and are
Empty, all users can use the AT command.
Batch Command
? Function: To schedule one or more commands in a system load
Run once at light time (normally the load is lighter
The load is reduced to less than 0.8).
? Use method same as at
crontab command format
? Role: The crontab file required to generate the cron process
? 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.
crontab file format?
Minute hour Day-of-month month-of-year Day-of-week
Commands
? which
? Minute which minute of the hour [0~59]
? Hour which hour of the day [0~23]
? Day-of-month the day of January [1~31]
? Month-of-year January of the year [1~12]
? Day-of-week Day of the week [0~6]
? Commands executed by commands
For example:
Minutes Hours Day Month Week command/script
- 4 * * *
- 18 * * 2,5
0 18 * 1-3 2,5
* * 1-5/usr/bin/wall </etc/issue
* * 1-5/sbin/shutdown-h now
*/2 12-14 * 3-6,9-12 1-5/bin/cp-r/etc/backup/etc.20110111 2>/backup/etc.bak.err >/derv/null Note: */2 every 2 minutes
Writing precautions
? The choice cannot be empty, must fill in, do not know the value
Use the wildcard character * to indicate any time
? Each time field can specify multiple values, not even
The constant value is used, interval, continuous value with--interval.
? The command should give the absolute path
? The user must have permission to run the corresponding command or program
Additional: # Ps-le | grep Crond to see if the system is starting the Crond process
#/etc/rc.d/init.d/crond Start
# vi/etc/crontab//crontab configuration file
Crontab Application Examples
Application Examples:
# CRONTAB-E
* * 1-5/usr/bin/wall </ETC/MOTD
0 * * 1-5/sbin/init 5
0 0 1,15 * 1/bin/cp-r/etc/backup/etc.0111
* crontab files can be established later to/var/spool/cron.
Catalog Confirmation
Cron configuration file
Role: Restrict which users can use the crontab command
? /etc/cron.allow
? /etc/cron.deny
Process processing Mode
? Standalone standalone operation
Additional: # Netstat-an | grep "LISTEN" | More
? XINETD Process Hosting
Additional: # Ps-le | grep inetd
? ATD, Crond Scheduled Tasks