I want to implement ps command using only the files of Linux procfs, how can I do it?
I want to print it out similar to psaux on Linux, but I look forward to hearing from mastersㅜ<
root@raspberrypi:/proc# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.1 0.4 5420 3964 ? Ss 14:16 0:04 /sbin/init
root 2 0.0 0.0 0 0 ? S 14:16 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 14:16 0:00 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< 14:16 0:00 [kworker/0:0H]
root 7 0.0 0.0 0 0 ? S 14:16 0:00 [rcu_sched]
root 8 0.0 0.0 0 0 ? S 14:16 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? S 14:16 0:00 [migration/0]
root 10 0.0 0.0 0 0 ? S 14:16 0:00 [migration/1]
root 11 0.0 0.0 0 0 ? S 14:16 0:00 [ksoftirqd/1]
root 13 0.0 0.0 0 0 ? S< 14:16 0:00 [kworker/1:0H]
root 14 0.0 0.0 0 0 ? S 14:16 0:00 [migration/2]
root 15 0.0 0.0 0 0 ? S 14:16 0:00 [ksoftirqd/2]
root 17 0.0 0.0 0 0 ? S< 14:16 0:00 [kworker/2:0H]
root 18 0.0 0.0 0 0 ? S 14:16 0:00 [migration/3]
root 19 0.0 0.0 0 0 ? S 14:16 0:00 [ksoftirqd/3]
root 21 0.0 0.0 0 0 ? S< 14:16 0:00 [kworker/3:0H]
root 22 0.0 0.0 0 0 ? S< 14:16 0:00 [khelper]
root 23 0.0 0.0 0 0 ? S 14:16 0:00 [kdevtmpfs]
root 24 0.0 0.0 0 0 ? S< 14:16 0:00 [netns]
root 25 0.0 0.0 0 0 ? S< 14:16 0:00 [perf]
(Amendment) To obtain from /proc, understand the path pattern "/proc/[number]/[partial path]"procman page documentation first.
Partial path
status file
stat file: process information
3193 (VBoxHeadless) S 3135 3193 3134 0 -1 4202496 360568 0 406 0 3041427 6421688 0 0 20 0 25 0 3228 2759557120 302185 18446744073709551615 4194304 4218588 140736234964176 140736234950688 139806890640307 0 8192 4096 73728 18446744073709551615 0 0 17 12 0 0 8 0 0
statm file : This file is memory usage information.
905095 532797 529991 6 0 312198 0
© 2024 OneMinuteCode. All rights reserved.