Linux process Management (-)

Source: Internet
Author: User

I. Type of process

You can divide processes running on Linux systems into three different types:

Interactive process: a process initiated by a shell. The interactive process can be run either in the foreground or in the background.

Batch process: a process that is not associated with a specific terminal and is submitted to the waiting queue for sequential execution. Daemon: A process that runs in the background when Linux is initialized at startup and needs to be run.

Second, the process of the starting mode

Manual start

Foreground start: Is the most common way to manually start a process. In general, the user types a command "Ls-l", which has started a process and is a foreground process.

Background start: Manually starting a process directly from the background is less, unless the process is time consuming and the user is not in a hurry to need the results.

Ls–r/>list &

Scheduled start

The scheduled start-up is set up in advance, and the system starts itself according to user requirements.

Iii. viewing processes in the system

1. PS command

Function: PS command is used to display the process information of the system instantaneous, it can show the information about the process and process of the system when the user input PS command.

Format: PS [options]

[[Email protected]]$ PS shows the process of this account

[[Email protected]]$ ps–aux View system and all processes per user

Because Ps–aux lists all the processes that are running in the system, it is not easy to find a particular process. With grep command, you can do more with less: [[email protected] pp]$ Ps–aux|grep pp process of finding pp

PS command instructions for use:

Common parameters:

A: Show All processes

U: Show more detailed information

X: Shows all processes that contain other users.

Examples of Use:

Ps

Ps–au

Ps-aux

Ps–aux | More

Ps–aux | Grephttpd

Ps–aux >/tmp/ps.log

2, top command to monitor the use of system resources

Refreshed every 5 seconds, dynamic display

Press the U key: Enter the user name to view the user process

Press the K key: Enter the PID removal process

Iv. processes in the control system

1. Kill command and Killall command

The kill command not only kills the process, but also kills all the child processes of the process.

The format of the KILL command is: Kill–signalpid

Why to kill a process

The process is consuming excessive CPU time

The process locks 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

The user can also use the Killall command to kill the process, specifying the command name of the process to be killed after the Killall command, not the PID

Example: kill–9927 parameter-9: Force kill

2. Nice command

Nice

To specify a program's run priority

Format: Nice–n command

[[Email protected]]# Nice--5 myprogram&

Run MyProgram in the background with a priority of-5

where n is the specified priority for the process run, and the higher the value of N, the lower the priority of the process. N can take negative values to increase the run level.

3. Renice command

Renice

Change the priority of a running process

Format: Renice–n PID is the specified process

[[Email protected]]# renice--5 777

Change the running PID to 777 process priority to 5

4. Run the program in the background &, BG command

[Email protected] root]# cp–r/usr/* test&

Copy all subdirectories and files under the/usr directory to the/root/test directory and run them in the background

[[email protected] root]# FG is placed in the foreground and shows the execution process

Press CTRL + Z to suspend the run program

[[email protected] root]# BG then put the execution process back in the background

[[email protected] root]# jobs view suspended processes

5. 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)

6, automatically scheduled process tasks

Several commands for automatically starting a process

At scheduling a job to execute at a time

Batch schedules jobs to execute once when the system load is not heavy

The system load is greater than 1.5 and does not run.

Cron scheduling jobs that run periodically

7. At and Batch

The AT command is used to specify that a command is executed at a certain point in the format of the AT command: at [options] Time

At configuration file

Role: Restrict which users can use the AT command

/etc/at.allow

/etc/at.deny

The use of the batch command is similar to at, except that the user does not have to specify the time, and batch runs the command when the system load is less than 1.5.

8. Application Cron

The cron process searches the crontab file and loads the memory (the crontab file is the/etc/crontab file and the file named under the/var/spool/cron/directory with the user name)

After the cron process is started, it will first check if a user has set up the crontab file, and if not, release the system resource by going to the "hibernate" state

The cron process wakes up every minute, viewing the crontab file to determine whether there is currently a command to execute. At the end of the command execution, any output will be sent to the owner of the crontab as a message

The function and format of the crontab command

Role: The crontab file required to generate the cron process

Crontab's command format

Crontab[-u User] File

Crontab[-u user] {-l|-r|-e}

-l This option causes the current crontab to be displayed on the standard output

-R Delete Current crontab

-e Use the editor to edit the current crontab file.

The edited file will be installed automatically when the edit is finished.

Crontab file Format:

Minute Hour Day Month DayofWeek Command

The meaning of the field represented by the available range

Minute run the program in the first few minutes of every hour 0 ~ 59

Hour Run the program for the first hours of every day 0 ~23

Day days of the month run the program 1 ~ 31

Month months of every year run the program 1 ~ 12

dayof Week Run the program for the first day of every week 0~ 6

command specifies the program to be run enter the commands and parameters to execute

Example:

4 * * * Program

Specify a daily 4:20 Execute program command

3 9 * * Program

Specify 9th 3:50 of the month to execute the program command

1 0 8 9 * Program or

1 0 8 Sep * Program

Specify September 8 0:1 to execute program commands each year

9. How to create a scheduled task

If you need to bring the system to a maintenance state at 2, 4, 6 3 o'clock in the morning per week, reboot the system and set the file name to/root/reboot.cron:

1. Create a crontab

# echo "* * * 2,4,6 shutdown–r +10" >/root/reboot.cron

2. Install the/root/reboot.cron file using the crontab command

#crontab/root/reboot.cron Installation

[[Email protected]]# corntab–e

Create the root user's corn file

5514 * * * ls/root corn Content

[[Email protected]]$ crontab–e Create corn file for PP user

3018 * * * ll/home/pp corn Content

[[Email protected]]# crontab–r Delete root cron

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.