Pregunta

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?

¿Fue útil?

Solución

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

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top