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下找到其對應的相關信息的!比如從哪里啟動的,開了幾個文件……

轉載于:https://www.cnblogs.com/thrillerz/p/8758534.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/251990.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/251990.shtml
英文地址,請注明出處:http://en.pswp.cn/news/251990.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

四元素理解

旋轉變換_四元數 2017年03月29日 11:59:38 csxiaoshui 閱讀數:5686 1.簡介 四元數是另一種描述三維旋轉的方式,四元數使用4個分量來描述旋轉,四元數的描述方式如下: qsxiyjzk,(s,x,y,z∈?)i2j2k2ijk?1 四元數的由…

31、SAM文件中flag含義解釋工具--轉載

轉載:http://www.cnblogs.com/nkwy2012/p/6362996.html SAM是Sequence Alignment/Map 的縮寫。像bwa等軟件序列比對結果都會輸出這樣的文件。samtools網站上有專門的文檔介紹SAM文件。具體地址:http://samtools.sourceforge.net/SAM1.pdf很多人困惑SAM文…

《Head First設計模式》批注系列(一)——觀察者設計模式

最近在讀《Head First設計模式》一書,此系列會引用源書內容,但文章內容會更加直接,以及加入一些自己的理解。 觀察者模式(有時又被稱為模型-視圖(View)模式、源-收聽者(Listener)模式或從屬者模式&#xff…

PYPL 4 月排行:Python 最流行,Java 還行不行?

開發四年只會寫業務代碼,分布式高并發都不會還做程序員? PYPL 發布了 4 月份的編程語言排行榜。 前五的分別是:Python、Java、Javascript、C# 和 PHP。可以看到,榜單沒有什么大變化,但是相比去年 4 月份,…

兩個向量的旋轉矩陣與四元素

兩向量的夾角 2017年06月20日 17:38:11 csxiaoshui 閱讀數:36764 怎么計算兩個向量間的夾角呢? 這里主要分兩種情況,對于二維向量和三維向量來分別討論。 1. 二維向量 二維向量的情況相對簡單,根據向量間的點乘關系 v1?v2|…

順序表

一、數據是如何在內存中存儲的? 32位系統中char,int型數據在內存中的存儲方式: char占1byte(8bit)int占4byte(32bit)假設我們有一個int類型的值,它從0x01開始,一個int占據…

Establishing SSL connection without server's identity verification is not recommended.

完全描述:Establishing SSL connection without servers identity verification is not recommended. According to MySQL 5.5.45, 5.6.26 and 5.7.6 requirements SSL connection must be established by default if explicit option isnt set. For compliance with existing …

四元素的真面目..........簡單粗暴

作者:Yang Eninala 鏈接:https://www.zhihu.com/question/23005815/answer/33971127 來源:知乎 著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。 根據我的理解,大多數人用漢密爾頓四元數就只…

2.自定義變量調節器

① 使用registerPlugin()方法來擴充變量調節器 該方法接收3個參數 1. 字符串modifier 2. 插件函數的名字 3. PHP回調函數 示例:自定義一個變量調節器,可以改變文字的顏色和大小 第一步:調用smarty對象的registerPlugin(&#x…

SpringBoot2構建基于RBAC權限模型的駕校代理小程序后端

本項目是使用SpringBoot2構建的一套基于RBAC權限模型的后臺管理系統,前端是微信小程序。 項目地址: github.com/fuyunwang/D… 項目的緣由 最近接了個外包,主要是針對于駕校開發一個代理小程序。目的是為了方便駕校的管理來招攬學員,同時方便維護學員和代理信息。 項…

while read line的問題

循環中的重定向或許你應該在其他腳本中見過下面的這種寫法&#xff1a;while read linedo…done < file剛開始看到這種結構時&#xff0c;很難理解< file是如何與循環配合在一起工作的。因為循環內有很多條命令&#xff0c;而我們之前接觸的重定向都是為一條命令工作的。…

Linemod;理解

Linemod 代碼筆記 2019年03月11日 16:18:30 haithink 閱讀數&#xff1a;197 最近了解到 Linemod 這個模板匹配算法&#xff0c;印象不錯 準備仔細學習一下&#xff0c;先做點代碼筆記&#xff0c;免得后面不好回顧 目前的筆記基本上把 核心流程都分析得比較清楚了&#xff0…

Swift3中數組創建方法

轉載自&#xff1a;http://blog.csdn.net/bwf_erg/article/details/70858865 數組是由一組類型相同的元素構成的有序數據集合。數組中的集合元素是有 序的&#xff0c;而且可以重復出現。 1 數組創建 在Swift語言中&#xff0c;數組的類型格式為&#xff1a; Array<ElementT…

BZOJ 5249: [2018多省省隊聯測]IIIDX(貪心 + 線段樹)

題意 這一天&#xff0c;\(\mathrm{Konano}\) 接到了一個任務&#xff0c;他需要給正在制作中的游戲 \(\mathrm{《IIIDX》}\) 安排曲目 的解鎖順序。游戲內共有\(n\) 首曲目&#xff0c;每首曲目都會有一個難度 \(d\) &#xff0c;游戲內第 \(i\) 首曲目會在玩家 Pass 第 \(\lf…

手眼標定

Eye-in-hand和Eye-to-hand問題求解和實驗 2018年12月07日 00:00:40 百川木易 閱讀數 3018 2018/12/5 By Yang Yang&#xff08;yangyangipp.ac.cn&#xff09; 本文所有源碼和仿真場景文件全部公開&#xff0c;點擊Gitee倉庫鏈接。 文章目錄 問題描述Eye-in-hand問題求解公式…

RNN總結

RNN既可以表述為循環神 經網絡&#xff08;recurrent neural network&#xff09;&#xff0c;也可以表述為遞歸神經網絡&#xff08;recursive neural network&#xff09;&#xff0c;前者一般用于處理以時間序列為輸入的問題&#xff08;比如把一個句子看成詞組成的序列&…

Problem 2. number題解

number&#xff1a;數學二分圖匹配 首先&#xff0c;如果S<N,那么S1&#xff0c;S2...N這些數直接放在S1,S2...N的位置上(如果其他數x放在這些位置上面&#xff0c;這些數不放在對應位置&#xff0c;那么x一定能放在這些數放的位置&#xff0c;所以直接交換即可)所以可以直接…

SSD列子

一、介紹 本博文主要介紹實現通過SSD物體檢測方式實現工件裂紋檢測。裂紋圖像如下所示&#xff1a; 二、關于SSD算法 具體算法不再闡述&#xff0c;詳細請參考&#xff1a; https://blog.csdn.net/u013989576/article/details/73439202 https://blog.csdn.net/xiaohu2022/arti…

linux硬鏈接與軟鏈接

Linux 系統中有軟鏈接和硬鏈接兩種特殊的“文件”。 軟鏈接可以看作是Windows中的快捷方式&#xff0c;可以讓你快速鏈接到目標檔案或目錄。 硬鏈接則透過文件系統的inode來產生新檔名&#xff0c;而不是產生新檔案。 創建方法都很簡單&#xff1a; 軟鏈接&#xff08;符號鏈接…

int轉時間

int轉時間 public static string FormatDuration(int duration) { if (duration 0) return "00:00:00"; int hours duration / 3600; int minutes duration % 3600 / 60; int seconds duration % 3600 % 60; string _hours hours.ToString("00") &qu…