nohup daemon process dies when terminal is close

I'm trying to copy the contents of a remote server to my local computer. Here is the command that I'm using:

nohup rsync -chavP -e 'ssh -p 23' --stats user@ipaddress:~/great/stuff /volume1/code > ~/rsynclog &

My understanding of the above command is that it should be creating a daemon process (nohup &) which is wholly disconnected from my terminal session. As such, I should be able to safely close my terminal and have the process continue on its merry way.

The process does start as expected. However, if I close my terminal session, the process no longer shows up in ps aux | grep rsync. The process has obviously died as you can see in the rsynclog:

receiving incremental file list
Killed by signal 1.
rsync error: unexplained error (code 255) at rsync.c(615) [Receiver=3.0.9]

This is happening as a direct result of my closing the terminal. If I leave the terminal open for hours then rsync works fine. As soon as I close it, however, the process dies.

Does anyone know enough about nohup to explain why it doesn't seem to be working here? I'm creating the terminal using PuTTY in Windows, but I also tried it through a terminal on my ubuntu machine and got the same result.

I tried a simpler test with nohup sleep 100000 & and this DID work! However, it is unclear to me why that daemon keeps living while rsync dies...

0
задан 18 June 2017 в 23:14
3 ответа

nohup не отключает процесс от входного терминала, но команда sleep ничего не читает из stdin, поэтому он продолжит работу, пока rsync читает stdin, поэтому, когда вы закроете терминал, он отсоединится от этого терминала, и rsync получит EOF или EIO.

Попробуйте выполнить nohup cat & , чтобы увидеть аналогичную ошибку в nohup.out.

Попробуйте использовать . Если это не сработает, вам нужно будет использовать экран .

Также проверьте https://unix.stackexchange.com/questions/31824/how-to-attach-terminal-to -detached-process

0
ответ дан 4 December 2019 в 16:13

Используйте screen или tmux . Это не способ сделать это.

1
ответ дан 4 December 2019 в 16:13

Я бы также рекомендовал screen для длительных заданий, но вы также можете использовать встроенную команду BASH disown для удаления заданий из текущей оболочки.

# help disown
disown: disown [-h] [-ar] [jobspec ...]
    Remove jobs from current shell.

    Removes each JOBSPEC argument from the table of active jobs.  Without
    any JOBSPECs, the shell uses its notion of the current job.

Options:
  -a    remove all jobs if JOBSPEC is not supplied
  -h    mark each JOBSPEC so that SIGHUP is not sent to the job if the
    shell receives a SIGHUP
  -r    remove only running jobs

Exit Status:
Returns success unless an invalid option or JOBSPEC is given.
0
ответ дан 4 December 2019 в 16:13

Теги

Похожие вопросы