Unix / Linux: Print IO Statistics of Running dd Process

Let’s say you have a dd process that is running. By default, dd will only print IO statistics once the job has been completed or if it is interrupted by a Ctrl-C (SIGINT) command. While the job is running, you will probably have no idea how much data has been copied, the current progress or the copying speed. But fret not, there is actually a way to get the IO statistics of a running dd process.

First, get the process id (PID) of the dd command that is running using the ps command.

$ ps -ef | grep -w dd
ibrahim   2965  2755 67 18:10 pts/0    00:00:03 dd if=/dev/zero of=/tmp/zerofile bs=4M count=1000

Based on the above output, we know that the PID of the dd process is 2965. Now, we can print the IO statistics of the dd process by sending the signal SIGUSR1 or USR1 to the process.

$ kill -USR1 2965
511+0 records in
511+0 records out
2143289344 bytes (2.1 GB) copied, 7.66307 s, 280 MB/s

From the above output, you can see that 2.1GB of data has been copied at a rate of 280 MB/s. The kill command will not terminate the dd process. Instead, it will simply send a signal to the dd process to inform the process to print the IO statistics to the standard error (stderr) stream . This procedure is documented in the dd man pages.

If you do not want to mess around with ps to get the process id of the dd process, then the below syntax will be helpful. It starts the dd process as a background job and assigns the variable “$pid” to the process id of the dd process. The variable is then used in the kill command. This method will be particularly useful in shell scripts.

$ dd if=/dev/zero of=/tmp/zerofile bs=4M count=1000 & pid=$!
$ kill -USR1 $pid
511+0 records in
511+0 records out
2143289344 bytes (2.1 GB) copied, 7.66307 s, 280 MB/s

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }