Linux method example to view all information of the process

Linux method example to view all information of the process

There is a task process on the server. When we use ps -ef | grep task to view it, we can only get some basic information. If we need to know the corresponding file path and the complete path of the startup command, we will have no idea where to start.

Today I will teach you a method to view all the information of the process, including the full path of the startup command, the corresponding file full path and other information: ls -l /proc/PID

For example, when you use ps -ef | grep webhook to view the process, you can only get the following information:

> ps -ef | grep webhook
root 15902 1 0 Aug15 ? 00:00:00 python -u src/webhook.py
root 30639 30612 0 22:50 pts/0 00:00:00 grep --color=auto webhook

Then execute ls -l /proc/15902

> ll /proc/15902
dr-xr-xr-x 2 root root 0 Sep 18 22:52 attr
-rw-r--r-- 1 root root 0 Sep 18 22:52 autogroup
-r-------- 1 root root 0 Sep 18 22:52 auxv
-r--r--r-- 1 root root 0 Sep 18 22:52 cgroup
--w------ 1 root root 0 Sep 18 22:52 clear_refs
-r--r--r-- 1 root root 0 Aug 15 16:48 cmdline
-rw-r--r-- 1 root root 0 Sep 18 22:52 comm
-rw-r--r-- 1 root root 0 Sep 18 22:52 coredump_filter
-r--r--r-- 1 root root 0 Sep 18 22:52 cpuset
lrwxrwxrwx 1 root root 0 Aug 15 16:48 cwd -> /services/apps/webhook
-r-------- 1 root root 0 Sep 18 22:52 environ
lrwxrwxrwx 1 root root 0 Aug 15 16:48 exe -> /usr/bin/python2.7
dr-x------ 2 root root 0 Aug 15 16:48 fd
dr-x------ 2 root root 0 Sep 18 22:52 fdinfo
-rw-r--r-- 1 root root 0 Sep 18 22:52 gid_map
-r-------- 1 root root 0 Sep 18 22:52 io
-r--r--r-- 1 root root 0 Sep 18 22:52 limits
...

There are several main files we can focus on:

  • cwd: the directory where the file is located
  • exe: The full path to the command to be executed
  • environ: environment variables when executing commands

Replenish:

#lsof lists the current system open files, often used with the -i option to see which program occupies a port [root@bogon ~]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 6701 root 4u IPv6 64259 0t0 TCP *:http (LISTEN)
httpd 6702 apache 4u IPv6 64259 0t0 TCP *:http (LISTEN)
httpd 6703 apache 4u IPv6 64259 0t0 TCP *:http (LISTEN)
httpd 6704 apache 4u IPv6 64259 0t0 TCP *:http (LISTEN)
httpd 6705 apache 4u IPv6 64259 0t0 TCP *:http (LISTEN)
httpd 6706 apache 4u IPv6 64259 0t0 TCP *:http (LISTEN)
[root@bogon ~]# lsof -i:22
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 931 root 3u IPv4 20955 0t0 TCP *:ssh (LISTEN)
sshd 931 root 4u IPv6 20965 0t0 TCP *:ssh (LISTEN)
sshd 3926 root 3u IPv4 36374 0t0 TCP bogon:ssh->bogon:53436 (ESTABLISHED)
[root@bogon ~]# 


#Get all information about processes for all users on the terminal [root@bogon ~]# ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.4 128092 4724 ? Ss Jun25 0:03 /usr/lib/systemd/syste
root 2 0.0 0.0 0 0 ? S Jun25 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S Jun25 0:00 [ksoftirqd/0]
root 6 0.0 0.0 0 0 ? S Jun25 0:00 [kworker/u256:0]
root 7 0.0 0.0 0 0 ? S Jun25 0:00 [migration/0]
root 8 0.0 0.0 0 0 ? S Jun25 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? R Jun25 0:01 [rcu_sched]
root 10 0.0 0.0 0 0 ? S Jun25 0:00 [watchdog/0]
root 12 0.0 0.0 0 0 ? S< Jun25 0:00 [khelper]
root 13 0.0 0.0 0 0 ? S Jun25 0:00 [kdevtmpfs]
root 14 0.0 0.0 0 0 ? S< Jun25 0:00 [netns]
root 15 0.0 0.0 0 0 ? S Jun25 0:00 [khungtaskd]
root 16 0.0 0.0 0 0 ? S< Jun25 0:00 [writeback]
root 17 0.0 0.0 0 0 ? S< Jun25 0:00 [kintegrityd]
root 18 0.0 0.0 0 0 ? S< Jun25 0:00 [bioset]
root 19 0.0 0.0 0 0 ? S< Jun25 0:00 [kblockd]
root 20 0.0 0.0 0 0 ? S< Jun25 0:00 [md]
root 26 0.0 0.0 0 0 ? S Jun25 0:00 [kswapd0]
root 27 0.0 0.0 0 0 ? SN Jun25 0:00 [ksmd]
root 28 0.0 0.0 0 0 ? SN Jun25 0:00 [khugepaged]
root 29 0.0 0.0 0 0 ? S Jun25 0:00 [fsnotify_mark]
root 30 0.0 0.0 0 0 ? S< Jun25 0:00 [crypto]
root 38 0.0 0.0 0 0 ? S< Jun25 0:00 [kthrotld]
root 40 0.0 0.0 0 0 ? S< Jun25 0:00 [kmpath_rdacd]
root 41 0.0 0.0 0 0 ? S< Jun25 0:00 [kpsmoused]
root 43 0.0 0.0 0 0 ? S< Jun25 0:00 [ipv6_addrconf]
root 62 0.0 0.0 0 0 ? S< Jun25 0:00 [deferwq]
root 94 0.0 0.0 0 0 ? S Jun25 0:00 [kauditd]
root 233 0.0 0.0 0 0 ? S< Jun25 0:00 [mpt_poll_0]
root 234 0.0 0.0 0 0 ? S< Jun25 0:00 [ata_sff]
root 235 0.0 0.0 0 0 ? S< Jun25 0:00 [mpt/0]
root 241 0.0 0.0 0 0 ? S Jun25 0:00 [scsi_eh_0]
root 243 0.0 0.0 0 0 ? S< Jun25 0:00 [scsi_tmf_0]
root 245 0.0 0.0 0 0 ? S Jun25 0:00 [scsi_eh_1]
root 246 0.0 0.0 0 0 ? S Jun25 0:00 [kworker/u256:2]
. . . . . .


#Get all process numbers of a service program [root@bogon ~]# pgrep httpd
6701
6702
6703
6704
6705
6706
#Kill the process, killall kills all processes by program name [root@bogon ~]# killall httpd
[root@bogon ~]# pgrep httpd
[root@bogon ~]# 
#kill kill program [root@bogon ~]# cat a.sh #Dead loop #!/bin/bash
while true
do
  echo "linux">/dev/null
done
[root@bogon ~]# ./a.sh
^Z
[1]+ Stopped ./a.sh
[root@bogon ~]# ps
  PID TTY TIME CMD
 3930 pts/1 00:00:00 bash
 11719 pts/1 00:00:01 a.sh
 11729 pts/1 00:00:00 ps
[root@bogon ~]# kill 11719 #I discovered this problem by accident, the reason is not clear yet [root@bogon ~]# ps
  PID TTY TIME CMD
 3930 pts/1 00:00:00 bash
 11719 pts/1 00:00:01 a.sh
 11733 pts/1 00:00:00 ps
[root@bogon ~]# kill -9 11719 #Since ordinary kill cannot kill, send -9 signal to force kill directly, the problem is solved [root@bogon ~]# ps
  PID TTY TIME CMD
 3930 pts/1 00:00:00 bash
 11734 pts/1 00:00:00 ps
[1]+ Killed ./a.sh
[root@bogon ~]# ./a.sh &
[1] 11735
[root@bogon ~]# ps
  PID TTY TIME CMD
 3930 pts/1 00:00:00 bash
 11735 pts/1 00:00:01 a.sh
 11736 pts/1 00:00:00 ps
[root@bogon ~]# kill 11735 #Ordinary background running programs can be killed directly
[root@bogon ~]# ps
  PID TTY TIME CMD
 3930 pts/1 00:00:00 bash
 11737 pts/1 00:00:00 ps
[1]+ Terminated ./a.sh
[root@bogon ~]#

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • View the port number occupied by the process in Linux
  • How to view process stack information in Linux
  • How to view the number of file handles opened by a process and how to modify them in Linux
  • In-depth understanding of viewing process memory usage under Linux
  • 4 ways to view processes in LINUX (summary)

<<:  Detailed explanation of the use of Vue.js draggable text box component

>>:  MySQL installation and configuration method graphic tutorial (CentOS7)

Recommend

Detailed explanation of MySQL database transaction isolation levels

Database transaction isolation level There are 4 ...

Layui implements sample code for multi-condition query

I recently made a file system and found that ther...

XHTML introductory tutorial: Use of list tags

Lists are used to list a series of similar or rela...

Brief analysis of centos 7 mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar

Baidu Cloud Disk: Link: https://pan.baidu.com/s/1...

How to use the markdown editor component in Vue3

Table of contents Install Importing components Ba...

Introduction to installing and configuring JDK under CentOS system

Table of contents Preface Check and uninstall Ope...

Vue+express+Socket realizes chat function

This article shares the specific code of Vue+expr...

How to turn off eslint detection in vue (multiple methods)

Table of contents 1. Problem Description 2. Probl...

Detailed explanation of .bash_profile file in Linux system

Table of contents 1. Environment variable $PATH: ...

MySQL slow query optimization: the advantages of limit from theory and practice

Many times, we expect the query result to be at m...

Detailed explanation of the difference between $router and $route in Vue

We usually use routing in vue projects, and vue-r...

Examples of preview functions for various types of files in vue3

Table of contents Preface 1. Preview of office do...

Detailed explanation of the top ten commonly used string functions in MySQL

Hello everyone! I am Mr. Tony who only talks abou...

Design Theory: Ten Tips for Content Presentation

<br /> Focusing on the three aspects of text...

Coexistence of python2 and python3 under centos7 system

The first step is to check the version number and...