1.编写ps的命令查看当前操作系统所有进程任务的信息 PID PPID STAT COMMAND /proc/21/status 纯数字的文件夹都对应一个进程 1. 遍历目录(/proc) 2. 找到纯数字的目录名称 3. /proc/21/status 4. 读文件,解析 5. 打印
时间: 2023-06-06 17:08:00 浏览: 67
以下是对应纯数字目录下的进程信息:
PID:进程ID
PPID:父进程ID
STAT:进程状态(如S 表示休眠状态,R 表示正在运行,Z 表示僵尸状态等)
COMMAND:进程的命令名称
您可以使用以下命令来查看这些信息:
ps aux | awk '{print $2,$3,$8,$NF}' | grep -v PID
注意:这个命令不是一个完整的代码,您需要在您的操作系统上调整一些东西才能使其正常工作。
相关问题
/proc/PID/stat
The /proc/PID/stat file contains various statistics about the process with the specified PID. The file is a single line of text, with each field separated by a space.
The fields in the file are as follows:
1. pid - process ID
2. comm - name of the command that started the process
3. state - current state of the process (e.g. running, sleeping, etc.)
4. ppid - parent process ID
5. pgrp - process group ID
6. session - session ID
7. tty_nr - controlling terminal of the process
8. tpgid - ID of the foreground process group of the controlling terminal
9. flags - process flags (e.g. whether it is being traced, etc.)
10. minflt - number of minor faults (i.e. page faults that could be resolved without disk IO)
11. cminflt - number of minor faults of child processes
12. majflt - number of major faults (i.e. page faults that required disk IO)
13. cmajflt - number of major faults of child processes
14. utime - amount of time the process has spent in user mode
15. stime - amount of time the process has spent in kernel mode
16. cutime - amount of time waited-for children have been in user mode
17. cstime - amount of time waited-for children have been in kernel mode
18. priority - priority of the process
19. nice - nice value of the process
20. num_threads - number of threads in the process
21. starttime - time the process started, in jiffies (1/100th of a second)
22. vsize - virtual memory size of the process
23. rss - resident set size of the process (i.e. amount of physical memory it is using)
24. rsslim - current limit on the resident set size
25. startcode - address of the start of the code segment
26. endcode - address of the end of the code segment
27. startstack - address of the start of the stack
28. kstkesp - current value of the stack pointer
29. kstkeip - current value of the instruction pointer
30. signal - bitmap of pending signals for the process
31. blocked - bitmap of blocked signals for the process
32. sigignore - bitmap of ignored signals for the process
33. sigcatch - bitmap of caught signals for the process
34. wchan - address of the kernel function the process is currently waiting in
35. nswap - number of pages swapped to disk
36. cnswap - number of pages swapped to disk of child processes
37. exit_signal - signal to be sent to the parent process when the process exits
38. processor - CPU the process last ran on
39. rt_priority - real-time priority of the process
40. policy - scheduling policy of the process
Note: Some fields may be displayed as 0 if they are not applicable to the process or if they are not available. Also, the values for utime, stime, cutime, and cstime are given in clock ticks, which can be converted to seconds by dividing by the value of the system variable HZ (which is typically 100 on most systems).
proc/pid/stat
`/proc/pid/stat` 文件是一个包含进程状态信息的文本文件。其中 `pid` 是进程的进程ID。
该文件包含了以下信息:
1. 进程ID(pid)
2. 进程名(comm)
3. 进程状态(state)
4. 进程的父进程ID(ppid)
5. 进程组ID(pgrp)
6. 会话ID(session)
7. 终端控制进程ID(tty_nr)
8. 进程的进程组ID(tpgid)
9. 内核调度器分配给该进程的CPU编号(flags)
10. 最后执行的CPU编号(minflt)
11. 累计的次缺页异常数(cminflt)
12. 由于内存不足导致进程被挂起的次数(majflt)
13. 累计的主缺页异常数(cmajflt)
14. 进程自愿放弃CPU的次数(utime)
15. 进程被迫放弃CPU的次数(stime)
16. 进程在等待I/O完成时睡眠的时间(cutime)
17. 进程在等待子进程退出时睡眠的时间(cstime)
18. 进程开始运行到现在的时间(start_time)
19. 进程使用的物理内存大小(rss)
20. 进程占用的虚拟内存大小(vsize)
21. 进程使用的共享内存大小(shmem)
22. 进程使用的内存页数(num_pages)
23. 进程使用的最大共享内存大小(maxrss)
24. 进程的状态标志(flags)
25. 进程的调度优先级(priority)
26. 进程的nice值(nice)
27. 进程所属的实际用户ID(uid)
28. 进程所属的实际组ID(gid)
可以通过读取该文件了解进程的状态信息。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)