proc文件系統探索之proc根目錄下的文件 一 cmdline 命令行的參數
阿新 • • 發佈:2018-10-25
aps return getc 有用 travel latency make i++ 終端
在2.6.35源碼fs/proc/base.c中;http://lxr.linux.no/linux+v2.6.35/fs/proc/base.c
轉載自ChinaUnix博客:http://blog.chinaunix.net/uid-22666248-id-3040364.html
本文是根據 kerneltravel proc文件系統探索系列http://www.kerneltravel.net/?p=281 學習,具體實際操作的記錄 proc文件系統探索之proc根目錄下的文件 一 cmdline ======================================== 在proc根目錄下,以數字命名的目錄表示當前一個運行的進程,目錄名為進程的pid。其內的目錄和文件給出了一些關於進程的信息。
- ywx@ywx:/proc/1500$ ls
- ls: cannot read symbolic link cwd: Permission denied
- ls: cannot read symbolic link root: Permission denied
- ls: cannot read symbolic link exe: Permission denied
- attr cpuset latency mountstats sched status
- auxv cwd limits net schedstat syscall
- cgroup environ loginuid oom_adj sessionid task
- clear_refs exe maps oom_score smaps wchan
- cmdline fd mem pagemap stack
- comm fdinfo mountinfo personality stat
- coredump_filter io mounts root statm
- static const struct pid_entry tid_base_stuff[] = {
- 2907 DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
- 2908 DIR("fdinfo", S_IRUSR|S_IXUSR, proc_fdinfo_inode_operations, proc_fdinfo_operations),
- 2909 REG("environ", S_IRUSR, proc_environ_operations),
- 2910 INF("auxv", S_IRUSR, proc_pid_auxv),
- 2911 ONE("status", S_IRUGO, proc_pid_status),
- 2912 ONE("personality", S_IRUSR, proc_pid_personality),
- 2913 INF("limits", S_IRUSR, proc_pid_limits),
- 2914#ifdef CONFIG_SCHED_DEBUG
- 2915 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
- 2916#endif
- 2917 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
- 2918#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
- 2919 INF("syscall", S_IRUSR, proc_pid_syscall),
- 2920#endif
- 2921 INF("cmdline", S_IRUGO, proc_pid_cmdline),
- 2922 ONE("stat", S_IRUGO, proc_tid_stat),
- 2923 ONE("statm", S_IRUGO, proc_pid_statm),
- 2924 REG("maps", S_IRUGO, proc_maps_operations),
- 2925#ifdef CONFIG_NUMA
- 2926 REG("numa_maps", S_IRUGO, proc_numa_maps_operations),
- 2927#endif
- 2928 REG("mem", S_IRUSR|S_IWUSR, proc_mem_operations),
- 2929 LNK("cwd", proc_cwd_link),
- 2930 LNK("root", proc_root_link),
- 2931 LNK("exe", proc_exe_link),
- 2932 REG("mounts", S_IRUGO, proc_mounts_operations),
- 2933 REG("mountinfo", S_IRUGO, proc_mountinfo_operations),
- 2934#ifdef CONFIG_PROC_PAGE_MONITOR
- 2935 REG("clear_refs", S_IWUSR, proc_clear_refs_operations),
- 2936 REG("smaps", S_IRUGO, proc_smaps_operations),
- 2937 REG("pagemap", S_IRUSR, proc_pagemap_operations),
- 2938#endif
- 2939#ifdef CONFIG_SECURITY
- 2940 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
- 2941#endif
- 2942#ifdef CONFIG_KALLSYMS
- 2943 INF("wchan", S_IRUGO, proc_pid_wchan),
- 2944#endif
- 2945#ifdef CONFIG_STACKTRACE
- 2946 ONE("stack", S_IRUSR, proc_pid_stack),
- 2947#endif
- 2948#ifdef CONFIG_SCHEDSTATS
- 2949 INF("schedstat", S_IRUGO, proc_pid_schedstat),
- 2950#endif
- 2951#ifdef CONFIG_LATENCYTOP
- 2952 REG("latency", S_IRUGO, proc_lstats_operations),
- 2953#endif
- 2954#ifdef CONFIG_PROC_PID_CPUSET
- 2955 REG("cpuset", S_IRUGO, proc_cpuset_operations),
- 2956#endif
- 2957#ifdef CONFIG_CGROUPS
- 2958 REG("cgroup", S_IRUGO, proc_cgroup_operations),
- 2959#endif
- 2960 INF("oom_score", S_IRUGO, proc_oom_score),
- 2961 REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
- 2962#ifdef CONFIG_AUDITSYSCALL
- 2963 REG("loginuid", S_IWUSR|S_IRUGO, proc_loginuid_operations),
- 2964 REG("sessionid", S_IRUSR, proc_sessionid_operations),
- 2965#endif
- 2966#ifdef CONFIG_FAULT_INJECTION
- 2967 REG("make-it-fail", S_IRUGO|S_IWUSR, proc_fault_inject_operations),
- 2968#endif
- 2969#ifdef CONFIG_TASK_IO_ACCOUNTING
- 2970 INF("io", S_IRUGO, proc_tid_io_accounting),
- 2971#endif
- 2972};
- 打開一個終端:
- ywx@ywx:~/desktop$ cat hello.c
- #include <stdio.h>
- #include <wait.h>
- int main()
- {
- int i=0;
- for(i=0;i<100;i++)
- {
- printf("hello world\n");
- sleep(2);
- }
- return 0;
- }
- ywx@ywx:~/desktop$ gcc hello.c -o hello
- ywx@ywx:~/desktop$ ./hello one two
- hello world
- hello world
- ./hello^@one^@two^@
- ywx@ywx:~/desktop$ cat readcmd.c
- #include <stdio.h>// std io fopen() snprintf() feof() perrof()
- int main(int argc,char *argv[])
- {
- FILE *fp;
- char path[80];
- unsigned char ch;
- snprintf(path,80,"/home/ywx/desktop/cmdline");//將cmdline中內容寫入path數組中,並在path的結尾添 加字符結束符"\0"
- if((fp=fopen(path,"r")) == NULL)
- {
- perror("fopen");
- return 0;
- }
- while(!feof(fp)) //判斷當前操作位置是否為文件的末尾,如果是,返回一個非零值
- {
- ch=fgetc(fp);//從stream流中讀取一個字符,操作位置向下移動一個
- printf("%c %d\n",ch,ch);
- }
- fclose(fp);
- return 0;
- }
proc文件系統探索之proc根目錄下的文件 一 cmdline 命令行的參數