![]() Therefore, we need to extract the timestamp and the CPU usage from this output. We’ve terminated the top command by pressing Ctrl-C after four iterations.Īccording to this problem, we only need the CPU usage data. Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie ![]() ![]() Using the top Command to Print the Status of a Single Process in Batch Modeįor example, we can make the top command keep reporting the status of the mpv process every two seconds until we manually kill it: $ top -b -d 2 -p $(pidof mpv) Then, we can monitor the changes of the log file using the tail -f command: $ tail -f /tmp/log_ps.txtįri Sep 3 10:05:08 PM CEST 2021 :: mpv 40.9%įri Sep 3 10:05:10 PM CEST 2021 :: mpv 40.9%įri Sep 3 10:05:12 PM CEST 2021 :: mpv 41.0%įri Sep 3 10:05:14 PM CEST 2021 :: mpv 41.1%įri Sep 3 10:05:16 PM CEST 2021 :: mpv 41.2%įri Sep 3 10:05:18 PM CEST 2021 :: mpv 41.2%Īs the output shows, our script has written CPU usages of the mpv process to the specified log file every two seconds. Therefore, when we start the script, it’ll keep writing CPU usage of the given process to the log file until we terminate it manually.Īlso, we write the current time “ $(date)”, process name and PID “ $PNAME” together with the CPU usage data to the log file. The free command displays: Total amount of free and used physical memory Total amount of swap memory in the system Buffers and caches used by the kernel From your terminal window, issue the command free. We put the logging implementation in a “ while true…“. You may only need to see the amount of free and used memory on your system.
0 Comments
Leave a Reply. |