brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: pidstat -e watches a command only for as long as it runs

Linux
~/tips/tip-performance-pidstat-e-monitor-command

pidstat -u -r -d 1 -e tar czf /tmp/test.tar.gz ~/Documents

Starts a command and reports its CPU, memory and disk use every second until it ends.

To see what a single command does to CPU, memory and disk, I used to start it in one terminal and look at top in another. pidstat from the sysstat tools can start the command itself, report on it every second and stop when it ends.

Put -e last, followed by the program and its arguments. An interval is required:

pidstat -u -r -d 1 -e tar czf /tmp/test.tar.gz ~/Documents

The flags choose what to report. The man page says that with no flags only CPU activity is shown. -u is CPU, -r is memory (page faults and memory use), and -d is I/O: kB_rd/s and kB_wr/s are the kibibytes read from and written to disk per second, and iodelay is the block I/O delay of the task in clock ticks. The 1 is the interval in seconds.

You can also watch something that already runs, with -p and a PID, or the name of a command with -C. A count after the interval limits the number of reports, for example pidstat -d 1 5 prints five.

The caveat: -e needs a non-zero interval, and pidstat stops when the program terminates, so you only get what happened during that run. Short commands finish before you see more than a line or two. Also, pidstat is part of the sysstat project, so it may need installing first. For a ranking of which program wrote the most, iotop is the better fit.

Further reading: pidstat(1) manual page

Going deeper: Keep a domain pointed at your home with Cloudflare DDNS on Unraid

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link