Linux Basics - Process Management (centos 7)

First, the basic introduction and review process

  • In Linux, the program (codes) of each execution is called a process. Each process is assigned an ID number.
  • Each process will correspond to a parent, but the parent process can be replicated multiple sub-processes.
  • Each process may exist in two ways. Foreground and background, foreground process is called on the user's screen can currently operate. Background process is actually in operation, but the process can not be seen on the screen, usually performed using a background mode.

Display process

ps -aux
ps -aux | grep xxx (查找特定进程)

Here Insert Picture Description

In the START, S- sleep, s- indicates that the process is a session leader of the process, N- indicates that the process has a lower priority than normal priority, R- running, D- short-term wait, Z- zombie process, T - tracked or stopped.
Displayed in full format

ps -ef

Here Insert Picture Description

  • PPID: parent process ID
  • C: CPU for calculating the execution priority factor. A higher value is a CPU intensive process operation, reduce the execution priority; Smaller values ​​indicates that the process is I / O intensive operations, execution priority increases
  • TTY: Complete terminal name

Top
Top terminal command will display the current full-screen interactive interface process rankings, timely tracking CPU, memory and other system resources occupancy, refreshed every three seconds by default, its role is similar to windows task manager system. (Photo from Internet)
Here Insert Picture DescriptionHere Insert Picture Description

Second, the process is terminated

If a process executed when half needs to be stopped, or has gone down a lot of system resources, then you can consider stopping the process. Use the kill command to complete this task.

kill  进程号(功能描述:通过进程号杀死进程)
kill -9 进程号(强制)
killall 进程名称(功能描述:通过进程名称杀死进程,也支持通配符)

For example, there are multiple gedit editors, all close to:

killall gedit

View the process tree

pstree [选项]
  • PID display process: -p
  • -u: Displays the user

Third, the service management

Service (service) is the essence of the process, but is running in the background, usually listening on a port, waiting for requests from other programs, such as (mysql, sshd firewalls, etc.), so we called daemons. In CentOS7, a service operator command with the previous version are very different, with systemctl instead of the original service.

查看一个服务
systemctl status name.service
设置开启/关闭/重启
systemctl start name.service
systemctl stop name.service
systemctl restart name.service

These commands only temporarily turned on or off service after the system restart will fail, if you want to set up a service always open to enable / disable, use the following command.

设置开启/禁用
systemctl enable name.service
systemctl disable name.service

View the list of services

systemctl list-unit-files [| grep status/name]

status represented by status screening can take enabled, disabled, static, this state represents the only screening services; name represented by name screening, support fuzzy matching. This command is found in the boot of service state is enabled / disabled, instead of the current status.

查看已开放端口
firewall-cmd --list-all
查看现在的防火墙端口
firewall-cmd --zone=public --list-ports
开放/关闭端口号 port为端口号,重启后生效
firewall-cmd --zone=public --add-port=port/tcp --permanent
firewall-cmd --zone=public --remove-port=port/tcp --permanent

Fourth, with the boot command chkconfig

Here Insert Picture Description

There are seven kinds of Linux systems run level (runlevel): commonly used is the level 3 and 5

  • Run Level 0: system shutdown, the system can not be set by default to run level 0, or can not start properly
  • Run Level 1: single-user work status, root permission for system maintenance, prohibits remote login
  • Run level 2: multi-user state (not NFS), does not support network
  • Run Level 3: Full multi-user state (there are NFS), after landing into the console command line mode
  • Run Level 4: The system is not used, reserved
  • Run Level 5: X11 console After you log in GUI mode graphics
  • Run level 6: a normal system shutdown and restart, the default operating level can not be set to 6, or can not start properly
chkconfig --list        #列出所有的系统服务
chkconfig --list mysqld        #列出mysqld服务设置情况

You can give each service by chkconfig command each level is set to run from startup / shutdown

chkconfig --level httpd 2345 on        
#设置httpd在运行级别为2、3、4、5的情况下都是on(开启)的状态

Viewing System network conditions

netstat -anp
  • -an output according to a certain order
  • -p shows which processes call
Published 16 original articles · won praise 6 · views 616

Guess you like

Origin blog.csdn.net/weixin_45605341/article/details/104790047
Recommended