Process and scheduled task management under Linux

The relationship between program and process

Program: Executable code and data stored in hard disk, CD-ROM and other media
Statically saved code
Process: Program code running in CPU and memory
Dynamically executed code
PS: Parent and child process: Each program can create one or more processes

View process

ps a Display all process information under the current terminal
u Display process information in a user-oriented format
x Display process information of the current user under all terminals
-e Display all process information in the system
-l Display process information in long format
-f displays process information in full format.
Example: ps aux
ps -elf

PID: The digital ID of the process in the system, which is unique in the current system (PPID is the parent process of PID). It is the word that the program is manipulated and loaded into memory called dynamic allocation at the beginning of this year. Every time the program is executed, The operating system will be reloaded, and the PID will be different each time it is loaded.
PID and PPID are non-zero certificate
STAT: shows the current status of the process, such as S (sleep), R (running), Z (rigid), <(high priority), N (low priority), s (parent Process), + (foreground process)

View process dynamic information

The top command will display the process ranking in a full-screen interactive interface on the current terminal, and track system resource usage including cpu, memory, etc. in time. It is refreshed every 3s by default, which is similar to the task manager of Windows.
top

View process information

grep -l "XXX" Output the process and process number PID of XXX in the process name
-U aaa Output the process and process number performed by user aaa pid
-t tty Output the process and pid number running on tty1 terminal
Example: grep -l -U teacher -t tty1

View process tree

pstree -aup
a complete command information
u
lists the corresponding user name p lists the corresponding pid number

How the process is started

Manual start
Front desk start: the user enters the command and execute the program directly
Backstage start: add the "&" symbol at the end of the command line
[root ~]cp /dev/cdrom mycd.iso &
[1]28454
[2]

Process before and after scheduling

Ctrl + Z key combination
Suspend the current process, that is, transfer to the background and stop executing
Jobs command:
view the list of tasks in the background
fg command:
restore the background process to the foreground, you can specify the task number

Terminate the operation of the process

Ctrl + C key combination to
interrupt the command being executed

kill, killall command
kill is used to terminate the process with the specified PID number
killall is used to terminate all processes with the specified name
-9 option is used to force termination

The pkill command
terminates the corresponding process according to specific conditions.
Commonly used command options:
-U Terminate the corresponding process according to the user name the process belongs to
-t Terminate the corresponding process according to the terminal where the process is located
[root]# pgrep -l -U “hackli”
3045 bash
[ root ]# pkill -9 -U “hackli”
[root ]# pgrep -l -U “hackli” #The process is not shown

Plan task management

at command
One-time scheduled task
at [HH:MM] [yyyy-mm-dd] time, minute, year, month, day
Example: [root]# date
Sun May 7 10:33:13 EDT 2017
[root]# at 10:35 2017_05_07
at> pgrep -Uroot |wc -l> /tmp/ps.root
at>
Job1 cat sun May 7 10:35
Cat /tmp/ps.root
atq query at task
hypothesis atrm [number] delete one-time task plan

Crontab command

Install the preset time period (minutes, hours, days...) to repeat the command operation specified by the user

It is a periodic scheduled task. The
main configuration file is the
global configuration file, located in the file: /etc/crontab. The
system default settings, located in the directory: /etc/cron.*/User-defined
settings, located in the file: /var/spool/cron/user name

Manage crontab

Crontab -e edit task plan
/ means every interval [ /3 means every three minutes]

  • Stands for arbitrary meaning
  • Represents continuous meaning
    , represents discontinuous intervals
    crontab -l view task plan
    Crontab -r clears task plan

Guess you like

Origin blog.csdn.net/yuiLan0/article/details/108508654