![]() 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. We put the logging implementation in a “ while true…“.
0 Comments
Leave a Reply. |