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

JavaScript to achieve product query function

This article example shares the specific code of ...

TCP socket SYN queue and Accept queue difference analysis

First we must understand that a TCP socket in the...

Mysql Sql statement exercises (50 questions)

Table name and fields –1. Student List Student (s...

ReactHooks batch update state and get route parameters example analysis

Table of contents 1. How to update in batches Con...

What to do if you forget your Linux/Mac MySQL password

What to do if you forget your Linux/Mac MySQL pas...

How to create your own image using Dockerfile

1. Create an empty directory $ cd /home/xm6f/dev ...

How to view the IP address of Linux in VMware virtual machine

1. First, double-click the vmware icon on the com...

Vue implements top left and right sliding navigation

Navigation and other things are often used in dai...

Implementation and optimization of MySql subquery IN

Table of contents Why is IN slow? Which is faster...

Copy fields between different tables in MySQL

Sometimes, we need to copy a whole column of data...

When the interviewer asked the difference between char and varchar in mysql

Table of contents Difference between char and var...

Let IE6, IE7, IE8 support CSS3 rounded corners and shadow styles

I want to make a page using CSS3 rounded corners ...

Vue Element-ui table realizes tree structure table

This article shares the specific code of Element-...