Linux – Why does rsync forks itself? And why one such forked process is almost kinda idle (as seen in iotop)

commandlinuxrsync

This is referring to the matter stated here and I am also experiencing the same.

In one of my servers, I ran an rsync, to backup a huge directory (size greater than 300 Gb) to a different disk, mounted on same machine. The directory being rsynced contains thousands of directories and files. I issued a single rsync command, with 'nohup' and then pushed it in background using the '&' command. The complete command given on the remote bash shell (using putty) was:

nohup rsync -avh /some/local/dir /backup/ >> /opt/rsync.dec22.log &

Then just to check at what rate was the data being copied, I used 'iotop' command, and found that there were 3 rsync running with same parameters. On searching I found the link above which says that it is normal.

But doing an iotop to monitor only those and the only rsync processes running on the system, I see that one process is reading files, one is writing them, but one is idle. The behaviour seems to be good, as one process doing only one thing at a time, but what is the 3rd process doing (seen as the middle one in the image below)?

The iotop command I had used was:

iotop -p22250 -p22251 -p22252

Here is the screenshot for the iotop command output:

iotop command output showing 3 rsync process

I am asking this cause I use rsync a lot, and want to understand its behaviour for long term benefit. I even read the manual, but it says nothing of the forking.

Best Answer

rsync is a program designed to be a client and server. The server reads and the client writes. Imagine that instead of a single computer, you had computers over network, I'm sure it's lot more clear if you think that way.

Then there is the controller. As IO operations tend to come with certain amount of risk, an IO issue shouldn't cause total blocking or a crash. So, it creates a fork for each connection and sits in the background.