Process and scheduled task management

Posted by spiffy577 on Sat, 19 Feb 2022 07:04:04 +0100

Relationship between program and process


● executable codes and data stored in hard disk, optical disk and other media
● statically saved code in the file


● program code running in CPU and memory
● dynamically executed code
● parent and child processes: each program can create one or more processes

View process information ps command

ps aux

●View static process statistics
[root@localhost~]# ps aux

ps command - view static process statistics
Method 1:
ps aux
a: Displays all processes on the terminal, including those of other users.
u: Represents the user who listed the process.
x: Displays the processes of all terminals.
Explanation of each column:
USER: the USER of the process.
PID: ID of the process.
%CPU: percentage of CPU used by the process.
%MEM: percentage of memory used.
VSz: amount of virtual memory used by the process (KB).
RSS: amount of physical memory occupied by this process (KB).
TTY: terminal name of the starting process. Processes that are not started from the terminal are displayed as?
STAT: the state of the process (D: non interruptible sleep state: R: running state; S5: in sleep state, can be awakened; T: stopped state, may be suspended in the background or the process is in tracking and debugging state; z: Zombie process, the process has been suspended, but some programs are still in memory)
START: the START time when the process is triggered.
TIME: the actual running TIME of the process.
COMMAND: the start COMMAND of the process.

ps -elf

●View static process statistics
[root@localhost~]# ps -elf

Method 2: PS Elf
-e: Display all process information in the system.
-l: Displays process information in long format.
-f: Displays process information in a complete format.
Explanation of each column:
F: The system token assigned by the kernel to the process.
S: Status of the process.
UID: the user who started these processes.
PID: process ID of the process.
PPID: the process number of the parent process (if the process is started by another process).
C: CPU utilization in the process lifecycle.
PRI: the priority of the process (the higher the number, the lower the priority).
NI: the humility value is used to participate in the decision of priority.
ADDR: memory address of the process.
SZ: the approximate size of the swap space required if the process is swapped out.
WCHAN: if the process is sleeping, the system function name in sleep will be displayed.
STIME: the system time when the process started.
TTY: terminal device when the process starts.
TIME: the cumulative CPU TIME required to run the process.
CMD: start command of the process.

View process information top

top command

●View dynamic process ranking information
[root@localhost ~]# top

top Command - view process dynamic information
 The first line is the task queue information
11:06:48   system time
up 1:22    System run time
1 user     Number of currently logged in users
load average: 0.06,0.60, 0.48
 System load, that is, the number of tasks processed by the system in unit time. The last three values are the average values from 1 minute, 5 minutes and 15 minutes ago to now
 Second behavior process information
Tasks      Total processes
running    Number of running processes
sleeping   Number of dormant processes
stopped    Number of aborted processes
zombie     Number of dead processes
 Third behavior CPU Information
us         User occupancy
sy         Kernel occupancy
ni         Priority scheduling occupancy
id         free CPU,To understand the free CPU Percentage, mainly depends on%id part
wa         I/O Waiting for occupation
hi         Hardware interrupt occupation
si         Software interrupt occupation
st         Virtualization occupancy
 The fourth line is memory information
total      Total memory space
free       idle memory
used       Used memory
buff/cache The sum of physical memory and swap memory buffers
 The fifth behavior is to exchange information in space
total      Total switching space
free       Free swap space
used       Used swap space
avail Mem  Available physical space
Explanation of columns in process information area:
PID    process id
USER   User name of the process owner
PR     priority
NI     Humility value. Negative values indicate high priority and positive values indicate low priority
VIRT   Total amount of virtual memory used by the process, in kb
RES    Size of physical memory used by the process, in kb
SHR    Shared memory size in kb
s      Process status
%CPU   From last update to now CPU Time occupancy percentage
%MEM   Percentage of physical process memory used
TIME+  Used by the process CPU Total time, unit 1/100 second
COMMAND Command name/command line

View process information pgrep command

●Query process according to specific conditions PID information
[root@localhost ~]#pgrep -l "log"
2538 rsyslogd
2113 mcelog
[root@localhost ~]# pgrep -l -U teacher -t tty2
27483 bash
27584 vim

View process tree pstree command

How to start the process

Manual start

● front desk start: the user inputs the command and directly executes the program
● background start: add "&" symbol at the end of the command line
[root@localhost ~]# cp ldevlcdrom mycd.iso &

Front and back scheduling of process


● suspend the current process, that is, transfer to the background and stop execution

jobs command

● view the task list in the background

fg command

● restore the background process to the foreground operation, and the task serial number can be specified

[root@localhost ~]# jobs
[1]-Stopped    cp ldevlcdrom mycd.iso
[2]+ Stopped   top
[root@localhost ~]# fg 1

Terminate the operation of the process


● interrupt the command being executed

Kill, kill commands

● kill is used to terminate the process of specifying the PID number
● kill is used to terminate all related to the specified name
● - 9 option for forced termination

pkill command

● terminate the corresponding process according to specific conditions
● common command options:
-U: Terminate the corresponding process according to the user name of the process
-t: Terminate the corresponding process according to the terminal where the process is located

[root@localhost ~]# pgrep - -U "teacher"
3045 bash
[root@localhost~]# pkill -9 -u " teacher"
[root@localhost ~]# pgrep -l -U " teacher"

Scheduled task management at

at command

at [HH:MM] [yyyy-mm-dd]
[root@localhost ~]# date
Sun May 7 10:33:13 EDT 2017
[root@localhost ~]# at 10:352017-05-07
at> pgrep -U root | wc-l > /tmp/ps.root
job 1 at Sun May 7 10:35:00 2017
[root@localhost ~]# cat /tmp/ps.root

Schedule task management crontab

crontab command

● repeat the command operation specified by the user according to the preset time period (minute, hour, day, month, week)
● it is a periodic planned task
● main setting documents
Global configuration file in file: / etc/crontab
The default setting of the system is located in the directory: / etc/cron*/
User defined settings in file: / varlspool/cron / username

Manage crontab scheduled tasks

●Edit scheduled task
crontab -e [-u user name]
●View scheduled tasks
crontab - [-u user name]
●Delete scheduled task
crontab -r [-u user name]

Format of crontab task configuration

minuteThe value is any integer from O to 59
hourThe value is any integer from O to 23
dateThe value is any integer from 1 to 31
monthThe value is any integer from 1 to 12
weekThe value is any integer from O to 7. 0 or 7 represents Sunday
commandCommand or program script to execute
●crontab Task configuration
 Meaning minute hour date month week command
 Number range 0~59   0~23  1~31  1~12  0~7   Commands to execute
#When the number of weeks is 0 or 7, it means "Sunday".
●crontab -e [-u root]
1.The rule is executed regularly every minute:
Every 1 minute:*/1 * * * *perhaps* * * * *
Every 5 minutes:*/5* * * *
2.The rule is executed regularly every hour:
Execute every hour:0 * * * * Or 0 */1 * * *
Every day at 7 am:0 7 * * *
Every day at 7:10 a.m:10 7 * * *
3.Execute the rule regularly every day:
Execute 0 every day * * *
4.Execute the rule regularly every week:Execute 0 every week * * 1
5.Execute the rule regularly every month:Execute 0 0 1 every month * *
6.The rules are executed regularly once a year:Execute 0 0 1 1 every year *

Topics: Linux