Linux:进程实例信息(/proc)
2017-06-23 13:13
387 查看
Linux:进程实例信息(/proc)
问几个问题:1.怎么知道一个进程对应哪个可执行文件?
2.怎么知道一个进程的资源限制?
3.怎么知道一个进程所处的环境?
4.怎么知道一个进程打开了哪些文件?
……
可以查看/proc下面的内容。
实验环境:
[test1280@localhost ~]$ uname -a Linux localhost.localdomain 2.6.18-371.el5 #1 SMP Thu Sep 5 21:21:44 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux
首先我建立一个myfile文件,然后tail -f:
[test1280@localhost 20170623]$ ll 总计 0 -rw-rw-r-- 1 test1280 test1280 0 06-23 10:02 myfile [test1280@localhost 20170623]$ tail -f myfile
这个时候就会挂起啦==》
我们重新开一个终端:
[test1280@localhost ~]$ ps -ef | grep test1280 | grep tail test1280 14603 11101 0 12:51 pts/12 00:00:00 tail -f myfile test1280 14611 14568 0 12:51 pts/0 00:00:00 grep tail
看到没?tail的进程PID是14603==》
如何看进程14603对应的进程信息呢?
[test1280@localhost ~]$ cd /proc/14603/ [test1280@localhost 14603]$ ll 总计 0 dr-xr-xr-x 2 test1280 test1280 0 06-23 12:56 attr -r-------- 1 test1280 test1280 0 06-23 12:56 auxv -r--r--r-- 1 test1280 test1280 0 06-23 12:51 cmdline -rw-r--r-- 1 test1280 test1280 0 06-23 12:56 coredump_filter -r--r--r-- 1 test1280 test1280 0 06-23 12:56 cpuset lrwxrwxrwx 1 test1280 test1280 0 06-23 12:56 cwd -> /home/test1280/20170623 -r-------- 1 test1280 test1280 0 06-23 12:56 environ lrwxrwxrwx 1 test1280 test1280 0 06-23 12:56 exe -> /usr/bin/tail dr-x------ 2 test1280 test1280 0 06-23 12:51 fd dr-x------ 2 test1280 test1280 0 06-23 12:56 fdinfo -r-------- 1 test1280 test1280 0 06-23 12:56 io -r--r--r-- 1 test1280 test1280 0 06-23 12:56 limits -rw-r--r-- 1 test1280 test1280 0 06-23 12:56 loginuid -r--r--r-- 1 test1280 test1280 0 06-23 12:56 maps -rw------- 1 test1280 test1280 0 06-23 12:56 mem -r--r--r-- 1 test1280 test1280 0 06-23 12:56 mounts -r-------- 1 test1280 test1280 0 06-23 12:56 mountstats -r--r--r-- 1 test1280 test1280 0 06-23 12:56 numa_maps -rw-r--r-- 1 test1280 test1280 0 06-23 12:56 oom_adj -r--r--r-- 1 test1280 test1280 0 06-23 12:56 oom_score lrwxrwxrwx 1 test1280 test1280 0 06-23 12:56 root -> / -r--r--r-- 1 test1280 test1280 0 06-23 12:56 schedstat -r--r--r-- 1 test1280 test1280 0 06-23 12:56 smaps -r--r--r-- 1 test1280 test1280 0 06-23 12:51 stat -r--r--r-- 1 test1280 test1280 0 06-23 12:56 statm -r--r--r-- 1 test1280 test1280 0 06-23 12:51 status dr-xr-xr-x 3 test1280 test1280 0 06-23 12:56 task -r--r--r-- 1 test1280 test1280 0 06-23 12:56 wchan
捡重要的说==》
cmdline cwd -> /home/test1280/20170623 environ exe -> /usr/bin/tail fd limits
其实不用我说,一看就明白了…
cmdline:
cmdline指的就是字面意思:命令行==》
cat cmdline tail -f myfile
cwd:
cwd指的是那个命令在哪个目录下执行的,我实际是在
/home/test1280/20170623
这个目录下新建的myfile然后执行tail,所以这里的cwd就是指向上面的目录的。
lrwxrwxrwx 1 test1280 test1280 0 06-23 12:56 cwd -> /home/test1280/20170623
注意cwd是个软链接。
environ:
这个文件记录了进程的环境变量信息。
我们知道每个进程都是有自己的环境表的,那具体有啥呢?
[test1280@localhost 14603]$ cat environ HOSTNAME=localhost.localdomainTERM=xtermSHELL=/bin/bashHISTSIZE=1000SSH_CLIENT=10.1.93.79 65228 19222SMPDIR=/home/test1280/cmin02smsOLDPWD=/home/test1280SSH_TTY=/dev/pts/12USER=test1280LD_LIBRARY_PATH=:/home/test1280/cmin02sms/libLS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40 ……
当然:我们可以从这个文件中查找PWD的值,这个值应该是和cwd一样的,只不过cwd是个软链接。
exe:
不用解释了,可执行文件嘛:
[test1280@localhost 14603]$ ll exe lrwxrwxrwx 1 test1280 test1280 0 06-23 12:56 exe -> /usr/bin/tail
可见tail这个文件是在/usr/bin/tail下的。
fd:
文件描述符,可以看看有啥:
[test1280@localhost 14603]$ cd fd [test1280@localhost fd]$ ll 总计 0 lrwx------ 1 test1280 test1280 64 06-23 13:07 0 -> /dev/pts/12 lrwx------ 1 test1280 test1280 64 06-23 13:07 1 -> /dev/pts/12 lrwx------ 1 test1280 test1280 64 06-23 12:51 2 -> /dev/pts/12 lr-x------ 1 test1280 test1280 64 06-23 13:07 3 -> /home/test1280/20170623/myfile
14603这个进程打开了4个文件,其中012是标准的输入输出,3这个文件描述符对应的就是我刚刚的那个文件myfile嘛…
limits:
每个进程其实都有一组限制,限制进程的资源,可以查看limits获得信息:
[test1280@localhost 14603]$ ll limits -r--r--r-- 1 test1280 test1280 0 06-23 12:56 limits [test1280@localhost 14603]$ cat limits Limit Soft Limit Hard Limit Units Max cpu time unlimited unlimited seconds Max file size unlimited unlimited bytes Max data size unlimited unlimited bytes Max stack size 10485760 unlimited bytes Max core file size 0 unlimited bytes Max resident set unlimited unlimited bytes Max processes 29493 29493 processes Max open files 1024 1024 files Max locked memory 32768 32768 bytes Max address space unlimited unlimited bytes Max file locks unlimited unlimited locks Max pending signals 29493 29493 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0
可见此时不能生成core文件…..
小结下:
/proc/PID/cmdline
/proc/PID/cwd
/proc/PID/environ
/proc/PID/exe
/proc/PID/fd
/proc/PID/limits
另外,/proc还有cpu信息和内核信息啥的:
[test1280@localhost proc]$ pwd /proc [test1280@localhost proc]$ ll cpuinfo -r--r--r-- 1 root root 0 06-23 13:11 cpuinfo [test1280@localhost proc]$ ll version -r--r--r-- 1 root root 0 06-23 13:11 version [test1280@localhost proc]$ cat version Linux version 2.6.18-371.el5 (mockbuild@x86-008.build.bos.redhat.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-54)) #1 SMP Thu Sep 5 21:21:44 EDT 2013
分别是:
/proc/cpuinfo
/proc/version
要记得,知道一个进程的PID,是可以到/proc下找到其对应的相关信息的!比如从哪里启动的,开了几个文件……
相关文章推荐
- [Linux] 内核模块&proc使用 实例:统计所有进程的信息
- linux /proc/pid进程信息说明
- oom和oom-killer实例简介(内存用完和进程杀死)------顺便说说linux下的两个重要目录:/proc/kmsg和/var/log/messages
- linux /proc/pid进程信息说明
- Linux下进程信息/proc/pid/status的深入分析
- linux进程控制编程与守护进程编写实例
- Linux根据端口查进程信息
- linux查看系统进程信息命令 px,top详解
- 如何编写linux守护进程及详细实例
- linux 一个简单守护进程实例
- linux使用top命令查看系统进程信息
- Linux下获取进程完整路径(包括进程名)——完整实例代码实现
- 获取系统(linux)cpu信息以及进程信息
- Linux进程编程实例
- linux 性能检测 大多数性能检测信息都来自/proc
- proc 进程信息解析
- Linux下用fork()派生的子进程通过pipe管道通讯的实例详解("生产者-消费者"问题)
- 通过读proc等方式获取Linux系统状态信息的一些方法
- linux进程通信--有名管道(FIFO)(含实例代码)
- Microsoft SQL Server 实例上运行的进程的相关信息