Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using command & + disown instead of nohup

I've tried today to use the nohup command to execute an rsync command in order to process the copy of some files from a VM to another even if I close the console.

Then I said why not using rsync [parameters] & + disown %1

What's the difference between the two?

like image 715
Yassine El Aissaoui Avatar asked Nov 27 '17 18:11

Yassine El Aissaoui


People also ask

What is a use of command?

The USE command causes the z/OS® Debugger commands in the specified file or data set to be either performed or syntax checked. This file can be a log file from a previous session. The specified file or data set can itself contain another USE command.

How do I use Command Prompt?

Navigate to the folder you wish to open a command prompt in. Click the address bar at the top of the window. Type cmd into the address text box followed by the Enter key. The command prompt window will open directly in that folder right away.

What is a command line example?

The MS-DOS operating system and the command shell in the Windows operating system are examples of command-line interfaces. In addition, programming language development platforms such as Python can support command-line interfaces.

What can use for AT command?

Use this option to specify a remote computer name. The at command will schedule the running of command on the local computer if you don't specify a computer name. Use the /every switch to run command on specific days of the week or month. Use the /next switch to run command on the next occurrence of the day.


1 Answers

disown is the better practice (being built into the shell rather than depending on an external tool), but it requires more work: You need to redirect stdin, stdout, and stderr yourself (whereas nohup will do the redirection with a nohup.out name hardcoded if you haven't done it yourself).

Thus:

rsync "${args[@]}" </dev/null >logfile 2>&1 & disown -h "$!"

As a stylistic note, if the only use you make of the PID is passing it to disown, I do suggest putting the disown on the same line as the invocation, as done above: This ensures that the $! reference is to the background process forked immediately prior, even if future changes add more code, potentially forking other background processes, after the rsync is started. (On the other hand, if you want to refer to the PID later, you might put a variable assignment on the same line: rsync ... & rsync_pid=$!, then disown -h "$rsync_pid" on a separate line).

like image 102
Charles Duffy Avatar answered Oct 26 '22 14:10

Charles Duffy