How to get continuous logs of Linux top command to store

Viewed 23

I am running a process process_a in loop . I want to get top -H logs stored for all process_a running in loop.

top -b -H -p `pgrep -d, -f process_a` 

the above command gave logs for process_a for first loop only

is there a way to get to get top logs for upcoming loops as well ?

1 Answers

This script will repeat forever. I added the -n 1 option. This allows you to rerun the pgrep for each iteration. Note: I used init for the name of the process. Change that to process_a for yours.

#!/bin/sh

while [ true ]; do
    top -b -H -n 1 -p `pgrep -d, -f init`
    sleep 1
done
Related