https://blog.csdn.net/test1280/article/details/73632333
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
1
2
首先我建立一个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
1
2
3
4
这个时候就会挂起啦==》

我们重新开一个终端:

[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
1
2
3
看到没?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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
捡重要的说==》

cmdline
cwd -> /home/test1280/20170623
environ
exe -> /usr/bin/tail
fd
limits
1
2
3
4
5
6
其实不用我说,一看就明白了…

cmdline:

cmdline指的就是字面意思:命令行==》

cat cmdline
tail -f myfile
1
2
cwd:

cwd指的是那个命令在哪个目录下执行的,我实际是在

/home/test1280/20170623
1
这个目录下新建的myfile然后执行tail,所以这里的cwd就是指向上面的目录的。

lrwxrwxrwx 1 test1280 test1280 0 06-23 12:56 cwd -> /home/test1280/20170623
1
注意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
……
1
2
3
当然:我们可以从这个文件中查找PWD的值,这个值应该是和cwd一样的,只不过cwd是个软链接。

exe:

不用解释了,可执行文件嘛:

[test1280@localhost 14603]$ ll exe
lrwxrwxrwx 1 test1280 test1280 0 06-23 12:56 exe -> /usr/bin/tail
1
2
可见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
1
2
3
4
5
6
7
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
可见此时不能生成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
1
2
3
4
5
6
7
8
分别是:

/proc/cpuinfo
/proc/version

要记得,知道一个进程的PID,是可以到/proc下找到其对应的相关信息的!比如从哪里启动的,开了几个文件……

转载于:https://www.cnblogs.com/thrillerz/p/8758534.html

Linux:进程实例信息(/proc)相关推荐

  1. linux 进程参数文件 /proc/pid/cmdline 简介

    在proc根目录下,以数字命名的目录表示当前一个运行的进程,目录名为进程的pid.其内的目录和文件给出了一些关于进程的信息. ywx@ywx:/proc/1500$ ls ls: cannot rea ...

  2. Linux进程详细信息查看

    我们通过ps及top系列命令查看进程信息时,只能看到命令执行的相对路径,查不到的进程的详细信息(如绝对路径),那么这些信息到底如何查找呢? 其实,在Linux中,一切皆文本,那么每个进程的信息其实都在 ...

  3. 进程内存信息 /proc/[pid]/maps /proc/[pid]/smaps /proc/[pid]/status

    /proc/[pid]/maps /proc/[pid]/smaps /proc/[pid]/status

  4. linux进程存放 proc,Linux系统下proc目录详解

    1,.proc --- 一个虚拟文件系统 /proc 文件系统是一种内核和内核模块用来向进程 (process) 发送信息的机制 (所以叫做 /proc).这个伪文件系统让你可以和内核内部数据结构进行 ...

  5. [Linux] 内核模块proc使用 实例:统计所有进程的信息

    实例要求: 编写一个Linux的内核模块,其功能是遍历操作系统所有进程.该内核模块输出系统中:每个进程的名字.进程pid.进程的状态.父进程的名字:以及统计系统中进程个数,包括统计系统中TASK_RU ...

  6. linux查cpu命令4可以选择哪些运动,Linux 查看cpu 信息的命令及简单实例

    Linux 查看cpu 信息的命令及简单实例 有的时候领导会问你某个服务器是多少核的,多少线程的,是不是会懵了,下面教你怎么看cpuinfo 1.查看cpu个数: # cat /proc/cpuinf ...

  7. linux c 通过 pid 获取 进程相关信息 cmdline

    linux系统命令ps和top都是通过读取/proc/$PID 目录下的信息获取进程的相关信息, 它遍历/proc目录下的首字符为数字的目录,获取系统进程的信息. 我们经常会把pid写到/var/ru ...

  8. linux进程隐藏 hook readdir函数 挂载覆盖/proc/pid 目录

    前言 上篇介绍了如何在有源码的情况下,通过 argv[] 及 prctl 对进程名及参数进行修改,整篇围绕/proc/pid/目录和 ps.top 命令进行分析,做到了初步隐藏,即修改了 /proc/ ...

  9. linux里netstat与ps,理解proc目录与linux进程、ps命令、netstat命令的关系

    零.proc目录简介 proc目录是虚拟文件系统(VFS)的一种实现,保存了进程信息(pid目录)和一些系统信息. 一.系统的信息 1.cpuinfo和meminfo两个文件 查看CPU和内存相关信息 ...

最新文章

  1. Syncfusion教程:在Xamarin.Forms中创建数据输入表单 (3)
  2. Bean标签基本配置
  3. C语言程序设计——设计一个学生管理系统(完美运行的程序(●‘◡‘●))
  4. tornado.httpclient.HTTPClient()的用法
  5. Docker基础学习笔记01:Docker安装
  6. 95-140-106-源码-transform-算子filter
  7. 【总结】Dancing Links
  8. java执行python脚本并传递参数_从Java执行Python脚本存在参数传递问题
  9. 软考信息安全工程师好考吗?
  10. ElasticJob3.0整合SpringBoot,ElasticJob-Lite【ElasticJob入门篇】
  11. 小米6连接WIFI后无法联网,线刷教程
  12. SQL中MINUS的用法
  13. 串口调试助手源码java_Java串口调试助手工程源码
  14. 简单的方法保存微信语音
  15. RealSense D435 在ROS kinetic 下的配置
  16. 【2021】13 年终总结
  17. SpringBoot+MyBatis(动态数据源/分布式事务XA(Atomikos))
  18. 技术管理实战笔记-角色认知篇
  19. 状语从句不是简单句_上海中考状语从句专题-练习
  20. 数字营销社区:2022年中小企业SEO策略「Google SEO果园策略方案」

热门文章

  1. 关于车机互联方式的一点想法
  2. 阿里云存储OSS中设置上传文件content type
  3. Servlet3 -- Servlet异步处理
  4. asp.net 中ascx、asmx、ashx等文件类型说明
  5. 卡尔曼滤波(Calman Filter)基本原理
  6. 感知算法论文(二)Pelee: A Real-Time Object Detection System on Mobile Devices(2018)译文
  7. ios 图像翻转_在iOS 14中使用计算机视觉的图像差异
  8. 5g与edge ai_使用OpenVINO部署AI Edge应用
  9. 第一章 统计学概论
  10. 如何使能linux vivid