1

I've read this and several other articles but I can't figure this out. This is what I've put together:

  1. sudo nohup or nohup sudo (I've tried both) the command without the background & (so you can enter your password before detaching it)
  2. Enter the password
  3. ^Z then bg
  4. disown the pid (doesn't work for some reason)
  5. 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?

Community
  • 1
  • 1
jstm88
  • 3,335
  • 4
  • 38
  • 55

2 Answers2

3

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
chepner
  • 497,756
  • 71
  • 530
  • 681
0

You are not using disown correctly, the right argument should be the jobspec ('%' + job number).

In your example you should have disown %1 instead of disown 2458.

For listing your current shell jobs list, you can use the bash builtin jobs

  • Nope, it doesn't work. I can `disown %1` and it disappears from `jobs` but the process is still gone after a logout. This happens whether or not I use `sudo nohup ...` or just `sudo ...`. – jstm88 Feb 03 '14 at 17:33