For a school project I need to reprogram ps aux
command in C (Like the picture below):
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 168028 12052 ? Ss 06:20 0:07 /sbin/init splash
root 2 0.0 0.0 0 0 ? S 06:20 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? I< 06:20 0:00 [rcu_gp]
root 4 0.0 0.0 0 0 ? I< 06:20 0:00 [rcu_par_gp]
root 6 0.0 0.0 0 0 ? I< 06:20 0:00 [kworker/0:0H-kblockd]
root 9 0.0 0.0 0 0 ? I< 06:20 0:00 [mm_percpu_wq]
root 10 0.0 0.0 0 0 ? S 06:20 0:00 [ksoftirqd/0]
root 11 0.0 0.0 0 0 ? I 06:20 0:03 [rcu_sched]
root 12 0.0 0.0 0 0 ? S 06:20 0:00 [migration/0]
root 13 0.0 0.0 0 0 ? S 06:20 0:00 [idle_inject/0]
root 14 0.0 0.0 0 0 ? S 06:20 0:00 [cpuhp/0]
root 15 0.0 0.0 0 0 ? S 06:20 0:00 [cpuhp/1]
root 16 0.0 0.0 0 0 ? S 06:20 0:00 [idle_inject/1]
root 17 0.0 0.0 0 0 ? S 06:20 0:00 [migration/1]
root 18 0.0 0.0 0 0 ? S 06:20 0:00 [ksoftirqd/1]
root 20 0.0 0.0 0 0 ? I< 06:20 0:00 [kworker/1:0H-kblockd]
root 21 0.0 0.0 0 0 ? S 06:20 0:00 [cpuhp/2]
root 22 0.0 0.0 0 0 ? S 06:20 0:00 [idle_inject/2]
root 23 0.0 0.0 0 0 ? S 06:20 0:00 [migration/2]
root 24 0.0 0.0 0 0 ? S 06:20 0:00 [ksoftirqd/2]
I managed to reprogram all the column except %CPU and %MEM. Like the other one, I know my answer is in /proc//[stat|status] but I didn't know what values I need to take and what is the formula to calculate the percentage.
Any idea ?