Linux --- Process Management

introduction

  As a Windows system, there are processes that execute the program for each Linux system have become a process, each process is assigned a process ID.

  Each process will correspond to a parent, but the parent process can be replicated multiple sub-processes, such as www server.

  Each process may exist in two ways, foreground and background: Operating foreground process that is currently on the user's screen can be carried out, although the background process is in execution, but can not see the progress on the screen, usually open in the background.

  After the general system service will open as a background process, and will be resident in the system, know the shutdown until the end of the process.

1) display process performed by the system

  Check the instruction process using ps, with the general parameters are: ps -aux

  ps -a: shows all the current terminal process information

  ps -u: displays process information in a user-friendly format

  ps -x: display parameters of the background process

  

  ps -ef | more

  

  It is worth mentioning here is a Column C: where denotes a CPU for calculating the execution priority factor, the greater this number, indicates that the process is CPU intensive operations, will reduce the execution priority; whereas if smaller values ​​indicate the process is I / O intensive dizziness, priority execution will increase. 【important】

  If you know the process name, you can query the parent process ID by name:

  Show sshd process ID of the parent:

  

2) to terminate the process kill and killall

  If a major terminate a process execution, or some process consumes too many system resources, you can consider using the kill command to stop the process.

  ①, basic grammar

      kill [options] process ID to kill the process by process ID

      killall process name to kill process by process name, and also supports wildcards, which is useful when the system load is too large and become very slow.

      Common options: -9: that forcing process stops immediately

  ②, use cases

    Case 1: kick user unless the law

      For this reason I xshell landed ordinary users hadoop1

    

      View user process ID

    

      Kill the process

    

    At this point there will see XShell green to red, are excluded.

3) Check the process tree pstree

  pstree [options] can process information more intuitive point of view

  PID display process commonly used options :-p

       -u  显示进程的所属用户

  

4)服务(Service)管理

  服务(service)本质就是进程,但是是运行在后台的,通常都会监听某个端口,等待其他程序的请求,比如(mysql、sshd、防火墙)因此我们称之为守护进程,是Linux中的重要知识点

  

  service 服务名 【选项】

  选项处可填:start/stop/restart/reload/status,比如你可以使用service iptables status查看防火墙的状态,可以使用service iptables stop来关闭防火墙。

  关于关闭或启用防火墙,有个细节需要注意:通过上述方式关闭或启动服务知识临时的,当系统重启后,还是会到原来对该服务的设置,如果希望设置某个服务自启动或永久关闭,要使用chkconfig指令。

5)查看服务名

  方式一:指令 setup 就可以看到跳出窗口

  方式二:/etc/init.d/ 服务名  ls -l /etc/init.d

6)开机的流程说明

  Linux启动流程:

   开机==>BIOS ==>/boot牵引==>init进程1==>运行级别==>运行对应的服务

7)chkconfig指令

  通过chkconfig命令可以给每个服务的各个运行级别设置自启动/关闭

  ①、查看服务

    chkconfig --list

    chkconfig 服务名 --list

    chkconfig --level 5 服务名 on/off

  使用chkconfig重新设置服务后自启动或关闭,需要重启机器reboot才能生效

8)动态监控进程【重要】

  top与ps指令很相似,他们都用来显示正在执行的进程,但是top与ps的不同之处在于top指令会在执行一段时间后更新正在运行的进程。

  top【选项】

   常用选项:-d 秒数  指定top命令每个几秒更新一次,默认是3秒。

        -i   使top不显示任何闲置或者僵死进程

        -p  通过指定监控进程ID来监控某个进程的状态

  当指令top指令时可以进行交互:【比较重要】

  p  以CPU使用率排序,默认就是此项

  M  以内存的使用率排序

  N  以PID排序

  q  退出top

  u  提示你输入哪一位用户的进程

  k  同时要杀死的进程的进程号

9)查看系统网络情况 netstat 【重要】

  netstat 【选项】

  常用选项:-an  按一定的顺序排列输出

       -p    显示哪个进程在调用

  案例1:查看系统所有的网络服务

  

  q键退出

  案例2:查看服务名为sshd的服务信息

  

Guess you like

Origin www.cnblogs.com/superlsj/p/11609080.html