官术网_书友最值得收藏!

Monitoring processes using ps

We have used the command ps in the introduction. Let's learn more about it:

  • To list the process associated with our current Bash shell terminal, enter the following command:
    $ ps
    
  • To list processes along with the parent process ID associated with the current terminal, enter the following command:
    $ ps –f
    

    We can see the process ID in the PID column and the parent process ID in the PPID column in the preceding output.

  • To list processes with the parent process ID along with the process state, enter the following command:
    $ ps –lf
    

    In the preceding output, the column with S (state) shows the current state of a process, such as R for running and S for suspended state.

  • To list all the processes running in the operating system including system processes, enter the following command:
    $ ps –ef
    

    The process names in [] are kernel threads. If you are interested in more options to learn about the ps command, you can use the following command:

    $ man ps.
    

    To find a particular process, you can use the following command:

    $ ps –ef | grep "process_name"
    

    The command with grep will display the process with process_name.

  • If we want to terminate the running process, enter following command:
    $ kill pid_of_process_to_be_killed
    
  • Many a time, if the process is not killed by the $ kill command, you may need to pass additional option to ensure that the required process is killed, which is shown as follows:
    $ kill -9 pid_of_process_to_be_killed
    
  • We can terminate the process by the name of a process instead of using the process ID as follows:
    $ pkill command_name
    $ pkill sleep
    

    Or:

    $ pkill -9 command_name
    
  • To know more about various flags of kill, enter following command:
    $ kill –l
    

    This displays all the signals or software interrupts used by the operating system. When we enter the $ kill command, the operating system sends the SIGTERM signal to the process. If the process is not killed by this command, then we enter the following command:

    $ kill -9 process_name
    

    This sends SIGKILL to the process to be killed.

主站蜘蛛池模板: 怀宁县| 秭归县| 炉霍县| 渑池县| 汉川市| 册亨县| 固安县| 阜阳市| 德化县| 博罗县| 德令哈市| 青海省| 尖扎县| 油尖旺区| 尚义县| 鄂州市| 乐陵市| 湟中县| 五寨县| 岳阳市| 荆门市| 平阳县| 阳新县| 玉山县| 北安市| 板桥市| 枝江市| 焉耆| 梨树县| 海口市| 镇江市| 绵阳市| 石首市| 平顺县| 法库县| 甘谷县| 鱼台县| 高邮市| 五指山市| 正镶白旗| 富顺县|