Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using rsync in my own C++ program by issueing the command system("rsync -rauzvq root@host:/folder");

I use this for keeping multiple systems in sync.

Now I have the problem that when a remote host shuts off and there it was still rsync-ing with my program, my program hangs for the period of the TCP timeout. So I thought, I would adjust the TCP timeout parameter for the rsync socket, but I can't figure out how (--sockopts isn't working).

Another way of fixing this would involve making a forked system call and check whether the rsync pID still exists after a certain timeout, otherwise kill it. Only downside on this is that I can't check whether the process is genuinely syncing or just hanging on a TCP timeout?

So, what would you guys try?

share|improve this question
did you try the --timeout parameter? from the man page: --timeout=TIMEOUT This option allows you to set a maximum IO timeout in seconds. If no data is transferred for the specified time then rsync will exit. The default is 0, which means no timeout. – Hartmut Oct 4 '12 at 13:56
the timeout parameter is just for I/O requests (e.g. hard-disk access etc.), not TCP requests. – Evert Oct 4 '12 at 14:37
up vote 4 down vote accepted

In your command line, rsync is not talking TCP directly, it's relying on ssh for the transmission.

You can use:

RSYNC_RSH='ssh -o ConnectTimeout=2 -o ServerAliveInterval=2 -o ServerAliveCountMax=2' rsync ...
share|improve this answer
Good answer, final command I used: rsync -rauzvq -e "ssh -o ConnectTimeout=2 -o ServerAliveInterval=2 -ServerAliveCountMax=2" root@host:/folder . – Evert Oct 4 '12 at 14:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.