Linux:进程实例信息(/proc)
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下找到其对应的相关信息的!比如从哪里启动的,开了几个文件……
Linux:进程实例信息(/proc)的更多相关文章
- Linux进程操作信息
Linux进程操作简单小结 linux上进程有5种状态: 1. 运行(正在运行或在运行队列中等待) 2. 中断(休眠中, 受阻, 在等待某个条件的形成或接受到信号) 3. 不可中断(收到信号不唤醒和不 ...
- 如何灵活运用Linux 进程资源监控和进程限制
导读 每个 Linux 系统管理员都应该知道如何验证硬件.资源和主要进程的完整性和可用性.另外,基于每个用户设置资源限制也是其中一项必备技能. 在这篇文章中,我们会介绍一些能够确保系统硬件和软件正常工 ...
- Linux 进程资源用量监控和按用户设置进程限制
每个 Linux 系统管理员都应该知道如何验证硬件.资源和主要进程的完整性和可用性.另外,基于每个用户设置资源限制也是其中一项必备技能. 在这篇文章中,我们会介绍一些能够确保系统硬件和软件正常工作的方 ...
- Linux进程管理及while循环
目录 进程的相关概念 进程查看及管理工具的使用 Linux系统作业控制 调整进程优先级 网络客户端工具 bash之while循环 20.1.进程类型 守护进程 daemon,在系统引导过程中启动的进程 ...
- Linux 下Qt实现守护进程实例(转)
原文地址:Linux守护进程的编程方法(含实例) 作者:lingdxuyan 参考文献 Linux信号列表(zz) Linux 守护进程的编程方法 linux上编写守护进程的例程 Linux下后台守 ...
- linux下查看运行进程详细信息
通过ps及top命令查看进程信息时,只能查到相对路径,查不到的进程的详细信息,如绝对路径等.这时,我们需要通过以下的方法来查看进程的详细信息: Linux在启动一个进程时,系统会在/proc下创建一个 ...
- linux下查看进程的状态 /proc/[pid]/status
查看进程的状态: 1.查看进程的pid,以java为例:ps -ef | grep java 2.查看进程状态:cat /proc/[pid]/status 关键字: linux [root@loca ...
- 脚本_统计 Linux 进程相关数量信息
#!bin/bash#作者:liusingbon#功能:统计 Linux 进程相关数量信息,running(运行的进程),sleeping(睡眠中的进程),stoped(停止的进程),zombie(僵 ...
- linux 查看运行进程详细信息
Linux在启动一个进程时,系统会在/proc下创建一个以PID命名的文件夹,在该文件夹下会有我们的进程的信息 通过ll或ls –l命令即可查看. ll /proc/PID cwd符号链接的是进程运行 ...
随机推荐
- Intel x86_64 Architecture Background 1
首先讲一下什么是Intel x86,x86是指intel的开发的一种32位指令集,从386开始时代开始的一直沿用至今,是一种cisc指令集.x84_64是x86 CPU开始迈向64位的时候,有2选择: ...
- Python 学习 第一篇:数据类型(数字,集合,布尔类型,操作符)
Python语言最常用的对象是变量和常量,常量的值是字面意思,其值是不可变的,变量的值是可变的,例如,123,"上海"是常量,而a=1,a=2,其中a是变量名.内置的核心数据类型有 ...
- Sql_join left right
1.内连接inner join 只返回两张表中所有满足连接条件的行,即使用比较运算符根据每个表中共有的列的值匹配两个表中的行.(inner关键字是可省略的) ①传统的连接写法: 在FROM子句中列出所 ...
- MongoDB副本集(一主一备+仲裁)环境部署-运维操作记录
MongoDB复制集是一个带有故障转移的主从集群.是从现有的主从模式演变而来,增加了自动故障转移和节点成员自动恢复.MongoDB复制集模式中没有固定的主结点,在启动后,多个服务节点间将自动选举产生一 ...
- Git分支管理的策略梳理
当下最流行的版本管理系统应该是非Git莫属.相比同类软件,Git有很多优点,其中很显著的一点,就是版本的分支(branch)和合并(merge)十分方便.有些传统的版本管理软件,分支操作实际上会生成一 ...
- Samba共享目录的多用户权限设置案例
下面根据实际工作中遇到的一个共享目录的多用户权限需求案例来说明下Samba用户权限的设置. 一.需求场景领导:李一(liyi)正式员工(zhengshiyuangong):刘二二(liuerer).于 ...
- 这是一个数学题牛客训练赛E
题目描述 https://www.nowcoder.net/acm/contest/78/E 已知有一个n+1个数的数列,对于给定的A0和An ,当i满足当1<=i<=n-1时有 ...
- Leetcode——171.Excel表列序号【水题】
@author: ZZQ @software: PyCharm @file: leetcode171_Excel表列序号.py @time: 2018/11/22 15:29 要求: 给定一个Exce ...
- 四则运算安卓版ver.mk3
在原有的基础上做了些许改动以及添加了一点小功能,以下是代码: package com.example.add; import java.io.File; import com.example.add. ...
- FZU软工第五次作业-词组频率分析
目录 00.前言: 01.分工: 02.PSP表格: 03.解题思路描述与设计实现说明: 解题思路简述: 关键代码 04.附加题设计与展示: 设计的创意独到之处 实现思路 实现成果展示 05.关键代码 ...