Linux Learning Note 12: Process Management

Source: Internet
Author: User
Tags pkill

1. Review the process

First, use W to view the process:

[Email protected] ~]# w 05:22:23 up Min,  2 users,  load average:0.00, 0.02, 0.06USER TTY from              [EMA Il protected]   IDLE   jcpu   PCPU whatchenyr   tty1     : 0               05:08   14:38   2.35s  0.23s Pam:gdm-passwochanshuy pts/0    192.168.230.1    05:09    0.00s  0.15s  0.21s Sshd:chanshuyi

which

JCPU: The terminal code to differentiate, the terminal all related process execution, the CPU time consumed will be displayed here

PCPU: CPU time spent executing the program

What : actions the user is performing

load Averate: 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: user-restricted time.

If you want to view information about a user, you can use the "w [username]" command to view it.

Second, use the PS command to view:

Format: PS [parameter]

Parameter:-A shows all user processes

-U display user name and start time

-X shows no control of the terminal process

-e displays all processes, including those that do not control the terminal

-L long format display

-W wide line display, can be widened with multiple W

# PS  //view your own process #ps-le  //view details of all processes #ps--sort PID  //list The processes that belong to them and sort by PID [[email protected] ~]# Ps-aux | Head-5user       PID%cpu%MEM    VSZ   RSS TTY      STAT START time   commandroot         1  0.0  0.1  19360  1536?        Ss   05:07   0:01/sbin/initroot         2  0.0  0.0      0     0?        S    05:07   0:00 [kthreadd]root         3  0.0  0.0      0     0?        S    05:07   0:00 [migration/0]root         4  0.0  0.0      0     0?        S    05:07   0:00 [ksoftirqd/0]

Where PID: Process number, PPID: Process number of the parent process, TTY: process-initiated terminal

STAT: Process Current state, S sleep state, D non-interruptible sleep state, R run state, Z zombie State, T stop

NI: Process Priority

Time: Total times the CPU was started by the process since it 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

Note: Use the Pstree command to view information for all processes in a tree-like form

The third kind, with pgrep command:

Use the Pgrep command to view the PID of all processes initiated by a service, such as:

Pgrep httpd//view PID of all processes initiated by httpd

Fourth: Real-time view of process information

Format: Top

Parameters (Interactive parameters):

D Specify the time interval for refresh

C Displays the entire command line instead of displaying the command name

U view the process of the specified user

K Abort the process in progress

H or? : Get Help

R Reset Process Priority

s change the time interval of the refresh

W writes the current settings to the ~/.TOPRC file

2. Close the process

First, close a process:

Format: Kill [parameter] [process PID]

Parameters:-9 forced shutdown-1 restart process (more parameters can be viewed with kill-l parameters)

Example:

Kill 333  //Turn off PID 333 process KILL-1 333//Restart 333 process

Second, close all processes for a service:

Format: Killall/pkill [process name]

Example:

Killall httpd  //close httpd service Pkill httpd  //close httpd service

3. Specify process Priority

First, specify the priority of the program Nice:

Format: Nice [-n] [process name] where n in-n indicates priority

Example: mark checks if the command is correct

Nice-5 httpd   //Specifies the priority of the HTTPD process is 5
Nice--5 httpd//Specify the priority of the HTTPD process is-5

Second, change the priority of a running process Renice:

Format: renice N pid

Example:

RENICE-5 777  //a process with a PID of 77 is given a priority of-5

4, the use of nohup command

The Nohup command allows the user to continue execution after exiting the login, and the nohup command stores the executed data information and error information by default to the file Nohup.out.

Command format: nohup [command executed] &

Example:

Nohup Find/-name init* >/root/find.init2014 &

5. Process suspend and resume

Process hangs: Ctrl + Z

Process termination: Ctrl + C

To view a suspended process: jobs

Restore the process to the foreground to continue running: FG [number] (the number obtained by the jobs view)

Resume the process to the background to continue running: BG [number] (the number viewed by jobs)

Supplementary example: MARK

6. Scheduled Tasks

There are typically three types of scheduled tasks: At, batch, cron. At scheduling a job to execute at a time, batch schedules the job to execute once when the system is attached to it, and cron schedules the jobs to run periodically.

The first: At only one job is executed at a time

Format: at [-f filename] [time] set up a task

at-d [serial number] or ATRM [serial number] Delete a task

At-l or ATQ view tasks in a queue

There are two kinds of time format: absolute timing and relative timing method.

Example 1: Creating a task in an interactive way

[[email protected] ~]# at 22:02at> Wall helloat> <eot>job 5 at 2014-12-03 22:02[[email protected] ~]# atq5
   
    2014-12-03 22:02 a root
   

The script for adding tasks in this way will be stored in the:/var/spool/at directory.

Example 2: Creating a task in a file way

First create a file/etc/at.script, add the following content:

Wall "Hello, I ' m wall"

Then set up the task:

[Email protected] ~]# at-f/etc/at.script now+1 minutesjob 8 at 2014-12-03 22:12

Second type: Batch command

The batch command performs this task when the system is attached to a lighter (under 0.8 load).

The batch command is less used and does not introduce more.

The third type: crontab command

Command: crontab [parameter]

Parameter:-L Displays the current crontab

-R Delete the current crontab ( the entire crontab file will be deleted)

- e makes editing the current crontab file with the editor

Where Crontab file is in the format: Minute hour day-of-month month-of-year day-of-week commands

Crontab a crontab task for each action in the file.

To create a crontab task, you only need to edit the crontab file with the "crontab-e" command, inserting the statements to be executed at timed intervals:

3 * Wall Hello  //22:23 minutes on December 3 to execute this command

The crontab file is stored under/var/spool/cron with the user's name command. The root user's crontab file is:/var/spool/cron/root.

Write "*" on the writing of time, if not limited.

If you want to represent a continuous, such as January-March, use the "-" connection on the corresponding bit, for example: "1-3".

To represent side-by-side, such as 2 March, use "," in the corresponding bit, for example: "2,3".

If you want to do it every minute, hourly, monthly, every year, connect with "/".

Example:

*/1 * * * * Wall Hello  //means execute once per minute */2 * * * * Wall Hello  //indicates execution every 2 minutes (other hours, months, years similar) * * 1-3 * * Wall Hello//1-3 per year Each time * * * * 1,3 * * Wall Hello//= 1th per year, number 3rd executed once

Linux Learning Note 12: 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.