proc/processId/cmdline这个文件有何作用?

125 views
Skip to first unread message

Kermit Mei

unread,
Nov 17, 2009, 1:17:57 AM11/17/09
to Xiyou-Linux-Group, szlug
我读一个程序的代码时,发现了一些语句,对cmdline文件中的内容进行分析,请
问这个文件是干什么用的?

sprintf(s,"/proc/%d/cmdline", getpid());
fp=fopen(s,"r");
fgets(s,200, fp);
fclose(fp);

BTW:我也在google,有满意的结果会贴在这里。 前段时间看/proc相关内容,正好
再研究一下。


Have fun!

Kemrit Mei

Adam

unread,
Nov 17, 2009, 1:28:46 AM11/17/09
to 深圳 Linux Unix 用户组

See "Advanced Linux Programming" Chapter 07 /proc filesystem

http://www.advancedlinuxprogramming.com/alp-folder

这个入口点可以用来查看某个进程的运行命令,比如

/proc$ ps -ef | grep X
root 2897 2893 6 11:02 tty7 00:15:53 /usr/X11R6/bin/X :0 -
br -audit 0 -auth /var/lib/gdm/:0.Xauth -nolisten tcp vt7
$ cat 2897/cmdline
/usr/X11R6/bin/X:0-br-audit0-auth/var/lib/gdm/:0.Xauth-nolistentcpvt7

这里你可以看到X运行在2897号进程里面,他的启动命令是/usr/X11R6/bin/X:......

大头阿当
--
Adam

Kermit Mei

unread,
Nov 17, 2009, 1:33:36 AM11/17/09
to Xiyou-Linux-Group, szlug

这个应该是每个进程按照命令行传入时执行的命令和参数。这个目录下存储了当前
系统中运行的此进程的很多信息,还有几个没有搞明白……


Kermit Mei

unread,
Nov 17, 2009, 1:34:26 AM11/17/09
to Américo Wang, Xiyou-Linux-Group, szlug
On Tue, 2009-11-17 at 14:24 +0800, Américo Wang wrote:
> 2009/11/17 Kermit Mei <kermi...@gmail.com>:

> > 我读一个程序的代码时,发现了一些语句,对cmdline文件中的内容进行分析,请
> > 问这个文件是干什么用的?
>
> man 5 proc
>
> /proc/[pid]/cmdline
> This holds the complete command line for the process, unless the
> process is a zombie. In the latter case, there is nothing in
> this file: that is, a read on this file will return 0 charac‐
> ters. The command-line arguments appear in this file as a set
> of null-separated strings, with a further null byte ('\0') after
> the last string.

Thanks.


Kermit Mei

unread,
Nov 24, 2009, 3:53:04 AM11/24/09
to sz...@googlegroups.com

谢谢! 原来man里面有这些信息……汗!


Reply all
Reply to author
Forward
0 new messages