5

I know about nohup and it won't do what I want:

Example:

$ nohup sleep 600 2>/dev/null >/dev/null </dev/null&
[1] 21844
$ ps -ef | fgrep -e 'sleep
> TTY'
UID        PID  PPID  C STIME TTY          TIME CMD
me       21844 19313  0 09:37 pts/9    00:00:00 sleep 600

As you can see, sleep still has pts/9 as a controlling terminal. I don't want it to have any controlling terminal. Partly because the program I want to use (it isn't sleep if you haven't guessed) tries to open the controlling terminal to ask me questions and I want to see how it behaves if it can't. How do I make this happen?

3 Answers3

7

The utility setsid on Linux can do this. On Fedora it's part of the util-linux package. This is the same package that contains things like mount, mkfs, /usr/bin/kill, and other similar things.

1

This is a FreeBSD solution, but perhaps a similar technique will work for your OS.

I know cron isn't exactly the command line, but if you have a specific command list you want to run, cron can do that. You'll likely want to avoid having cron run the job repeatedly, perhaps by crafting a wrapper around your desired command list, something like:

#!/bin/sh
[ -f /tmp/my-semaphore-file ] || {
  touch /tmp/my-semaphore-file
  my_command_stack > /dev/null 2>&1
}

Inelegant perhaps for production use, but if you just want to test how your command stack performs with no controlling terminal, that will do it. The wrapper will not allow cron to run the command again until you:

rm /tmp/my-semaphore-file

at(1) is also an option, and is "almost" a command-line solution:

echo 'my_command_stack > /dev/null 2>&1' | at now+1 minute
Jim L.
  • 929
0

You need to also use disown to detach the process from the tty.

https://unix.stackexchange.com/questions/3886/difference-between-nohup-disown-and

Try running nohup sleep 600 2>/dev/null >/dev/null </dev/null& disown and see if that gives you the desired result.

zymhan
  • 812