The method of obtaining the File path of Linux process
Where can I find the Linux process file path, which sometimes makes the Linux system administrator take some thought. Here the editor says a simple case, which I believe will make many administrators gain something and help easily get the desired Linux process file path and complete the specified task.
Enter the / proc directory
Ps View process
Root 2227 5.6 1.4 328704 27252 pts/1 Rl+ 14:16 0:01 / usr/bin/python. / run.py
Use the ll command: ll process number
Ll / proc/2227
An example is shown below:
[root@aliyun proc] # ll 2227
Total 0
Dr-xr-xr-x 2 root root 0 Feb 16 14:19 attr
-rw-r--r-- 1 root root 0 Feb 16 14:19 autogroup
-r-1 root root 0 Feb 16 14:19 auxv
-root root Feb-1 Murray 0 Feb 16 14:19 cgroup
-- W1 root root 0 Feb 16 14:19 clear_refs
-root root Feb-1 Murray 0 Feb 16 14:16 cmdline
-rw-r--r-- 1 root root 0 Feb 16 14:19 comm
-rw-r--r-- 1 root root 0 Feb 16 14:19 coredump_filter
-root root Feb-1 Murray 0 Feb 16 14:19 cpuset
Lrwxrwxrwx 1 root root 0 Feb 16 14:19 cwd-> / vipkid/lianxi
-r-1 root root 0 Feb 16 14:19 environ
Lrwxrwxrwx 1 root root 0 Feb 16 14:17 exe-> / usr/bin/python2.7
Dr-x- 2 root root 0 Feb 16 14:16 fd
Dr-x- 2 root root 0 Feb 16 14:19 fdinfo
-rw-r--r-- 1 root root 0 Feb 16 14:19 gid_map
-r-1 root root 0 Feb 16 14:16 io
-root root Feb-1 Murray 0 Feb 16 14:19 limits
-rw-r--r-- 1 root root 0 Feb 16 14:19 loginuid
-root root Feb-1 Murray 0 Feb 16 14:19 maps
-rw- 1 root root 0 Feb 16 14:19 mem
-root root Feb-1 Murray 0 Feb 16 14:19 mountinfo
-root root Feb-1 Murray 0 Feb 16 14:19 mounts
-r-1 root root 0 Feb 16 14:19 mountstats
Dr-xr-xr-x 6 root root 0 Feb 16 14:19 net
Dr-x--x--x 2 root root 0 Feb 16 14:19 ns
-root root Feb-1 Murray 0 Feb 16 14:19 numa_maps
-rw-r--r-- 1 root root 0 Feb 16 14:19 oom_adj
-root root Feb-1 Murray 0 Feb 16 14:19 oom_score
-rw-r--r-- 1 root root 0 Feb 16 14:19 oom_score_adj
-root root Feb-1 Murray 0 Feb 16 14:19 pagemap
-root root Feb-1 Murray 0 Feb 16 14:19 personality
-rw-r--r-- 1 root root 0 Feb 16 14:19 projid_map
Lrwxrwxrwx 1 root root 0 Feb 16 14:19 root-> /
-rw-r--r-- 1 root root 0 Feb 16 14:19 sched
-root root Feb-1 Murray 0 Feb 16 14:19 sessionid
-root root Feb-1 Murray 0 Feb 16 14:16 smaps
-root root Feb-1 Murray 0 Feb 16 14:19 stack
-root root Feb-1 Murray 0 Feb 16 14:16 stat
-root root Feb-1 Murray 0 Feb 16 14:19 statm
-root root Feb-1 Murray 0 Feb 16 14:16 status
-root root Feb-1 Murray 0 Feb 16 14:19 syscall
Dr-xr-xr-x 4 root root 0 Feb 16 14:19 task
-rw-r--r-- 1 root root 0 Feb 16 14:19 uid_map
-root root Feb-1 Murray 0 Feb 16 14:19 wchan
The files under the process number directory under the / proc file system mirror the current running information of the process.
You can see from it:
The cwd symbolic link is the running directory of process 2227.
Exe symbolic connection is the absolute path to execute the program.
Cmdline is the command line command entered when the program is running; in this case:. / run.py
Cpu records the cpu; on which the process may be running to display virtual cpu information
Environ records the environment variables when the process is running
The fd directory is the symbolic link to the files opened or used by the process
...
Enter the process running directory directly through cwd. By viewing the relevant information, you can locate which port number this directory corresponds to, and which application uses this service program. This gives you the path to the Linux process file.