Linux process management, work management, system resource viewing, scheduled tasks

1: Process management

 

Process view

 

ps aux #View     all processes in the system. BSD operating system format

 a foreground process

 x background process

 u shows which user the process was created by

 

ps -le #View     all processes in the system. Linux standard format

 -l display more detailed information

 -e show all information

 

top #View the health status of the command

 

The first five lines of the top command are explained in the following pictures



 

 

 

 

 top command option

 pstree to view the process tree

Syntax: pstree [options]

Options:

   -p: show the PID of the process

   -u: show the user of the process

 

kill process

 

kill command

kill -l to view available process signals



 

eg: 

kill -1 88888 restart process number is 88888 process

kill -9 88888 Force close the process ID is 88888 

kill -15 88888 normally close the process number is 88888 process

 

killall command

kill process by process name

Syntax: killall [options] [signals] process name  

Options:

    -i: interactive, ask if you want to kill a process

    -I: ignore case of process names    

eg: killall -9 mongo forcibly kills the process whose process name is mongo

 

pkill command

kill process by process name

Syntax: pkill [options] [signals] process name

Options:

    -t terminal number: kick out the user according to the terminal number (used in conjunction with the w command)

eg: pkill -9 mongo forcibly kills the process whose process name is mongo

eg: pkill -9 -t tty1 forcibly kills the process logged in from the tty1 terminal

 

 

View a specified service in a tree view

pstree -p | grep mongo

 

Two: work management

put the process in the background

Method 1: Command &

Method 2: Press the ctrl+z shortcut key during the execution of the command

Note: The difference between Fa 1 and Fa Er is that Fa 1 will continue to run in the background, while Fa 2 will be suspended in the background.

 

See what's going on in the background

jobs command

Syntax: jobs [options]

Options:

    -l show the pid of the job

Note: The "+" sign represents the last job that was put into the background, and it is also the job that is restored by default when the job is resumed.

      "-" represents the second-to-last job put into the background

      

Foreground execution that resumes work suspended in the background

fg command

fg % job number

parameter:

    % job number: The % sign can be omitted, but pay attention to the difference between job number and PID.

    

Resume the work suspended in the background and execute it in the background

bg command

bg % job number

 

Three: check system resources

 vmstat command

View monitoring system resources

Syntax: vmstat [refresh delay refresh times]

eg: vmstat 1 3 Monitor system resources three times with one second interval each time.

 

dmesg command

Display kernel self-test information at boot time

Syntax: dmesg

eg:dmesg | grep CPU 

 

free command

Check the memory usage status

Syntax: free[options]

Options:

    -b in bytes

    -k KB in units  

    -m MB in units

    -g GB in units

   eg: free -g View memory usage in GB.

View CPU information

cat /proc/cpuinfo

 

uptime command

Viewing the system running time is equivalent to the first line of the top command. The w command can also see the same content.

 

View system and kernel related information

 

uname command

View system kernel version information command

Syntax: uname [options]

Options:

    -a View all relevant information of the system;

    -r View kernel version;

    -s View the kernel name;

    

Determine the current number of digits in the current system

file /bin/ls

 

Query the current release version of the Linux system

lsb_release -a

 

 

lsof command

List process open or use file information

Syntax: lsof [options]

Options:

    -c string: List only files opened by processes starting with the string

    -u username: only list files opened by a user's process

    -p PID: List files opened by a PID process

 

eg: lsof -c init # List processes related to init

 

Four: Scheduled task management

 Function: a, backup

           b, shut down

           c, restart, etc.

 

crond service (to ensure that the service is started, the scheduled task will take effect)

Check if crond is started: ps aux | grep crond

 

service crond start prompts "crond: unrecognized service" indicating that it is not installed

Install: yum install vixie-cron

Start crond on boot: ? ?


crontab command

Syntax: crontab [options]

Options:

    -e: Edit crontab timing user

    -l: Query crontab tasks

    -r: delete all crontab tasks of the current user

 

Five parameters of timed tasks

 

Special symbols for timed tasks

 

Timed task demo

 

eg:

* * * * * echo $(date) >> /temp/dingshi.log Write the current system time to the dingshi.log file every minute

30 18 * * 6 halt #Timely shutdown at 18:30 every Saturday.

30 18 * * 6 /sbin/shutdown -h now #Restart regularly at 18:30 every Saturday. 

# Note: -h parameter is shutdown -r parameter is restart.

If shutdown: command not found error, use whereis shutdown to find the path. Reference article: http://www.jb51.net/article/15008.htm

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326577693&siteId=291194637