Issue
I've read this and several other articles but I can't figure this out. This is what I've put together:
sudo nohup
ornohup sudo
(I've tried both) the command without the background&
(so you can enter your password before detaching it)- Enter the password
^Z
thenbg
disown
the pid (doesn't work for some reason)- Log out
Here's the output:
[user@localhost ~]$ nohup sudo dd if=/dev/zero of=/dev/sda bs=1M
nohup: ignoring input and appending output to ‘nohup.out’
[sudo] password for user:
^Z
[1]+ Stopped nohup sudo dd if=/dev/zero of=/dev/sda bs=1M
[user@localhost ~]$ bg
[1]+ nohup sudo dd if=/dev/zero of=/dev/sda bs=1M &
[user@localhost ~]$ sudo ps | grep dd
2458 pts/32 00:00:00 dd
[user@localhost ~]$ disown 2458
-bash: disown: 2458: no such job
[user@localhost ~]$ logout
Connection to [server] closed.
$ remote
Last login: Mon Feb 3 11:32:59 2014 from [...]
[user@localhost ~]$ sudo ps | grep dd
[sudo] password for user:
[user@localhost ~]$
So the process is gone. I've tried a few other combinations with no success. Any ideas to make this work?
Solution
Use the -b
option to sudo
to instruct it to run the given command in the background. Job control doesn't work because the nohup
process is not a child of the current shell, but of the sudo
process.
sudo -b nohup dd if=/dev/zero of=/dev/sda bs=1M
Answered By - chepner Answer Checked By - Gilberto Lyons (WPSolving Admin)