How do I detach from a controlling terminal from the command line?

Omnifarious

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?

Jim L.

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I detach a screen session from a terminal?

From Dev

How do I install NetDrive from a Linux command line (terminal)?

From Dev

How do I detach JProfiler from Eclipse?

From Dev

How do i detach this fan from the heatsink?

From Dev

Invoke a command/script disconnected from the controlling terminal?

From Dev

How can I print output whilst detached from controlling terminal?

From Dev

How do I retrieve only the needed line from terminal output?

From Dev

How do I execute a command in an iTerm window from the command line?

From Dev

How do I pass a username to an FTP command from the command line?

From Dev

how to push to git from Terminal / Command Line

From Dev

How detach repl from starting terminal/thread?

From Dev

How to remotely detach a screen from another terminal

From Java

How do I force detach Screen from another SSH session?

From Dev

How to launch gedit from terminal and detach it (just like "subl" command works)?

From Java

How do I drop a MongoDB database from the command line?

From Java

How do I launch the Android emulator from the command line?

From Dev

How do I run a gui app from the command line?

From Dev

How do I read arguments from the command line with an MPI program?

From Dev

How do I open a file with Chrome from the command line?

From Dev

How do I get the default font from the command line?

From Dev

How do I upgrade releases from a Live USB with the command line?

From Dev

How do I install the latest version of cmake from the command line?

From Dev

How do I start the Privacy and Activity Manager from command line?

From Dev

How do I make pip available from command line mac?

From Dev

How do I build boost 1.55 from the command line with mingw?

From Dev

How do I control the WMP from command line/batch

From Dev

How do I open a WinSCP GUI session from command line?

From Dev

How do I add multiple "+" commands into less from the command line

From Dev

How do I download mail folders from command line?

Related Related

  1. 1

    How do I detach a screen session from a terminal?

  2. 2

    How do I install NetDrive from a Linux command line (terminal)?

  3. 3

    How do I detach JProfiler from Eclipse?

  4. 4

    How do i detach this fan from the heatsink?

  5. 5

    Invoke a command/script disconnected from the controlling terminal?

  6. 6

    How can I print output whilst detached from controlling terminal?

  7. 7

    How do I retrieve only the needed line from terminal output?

  8. 8

    How do I execute a command in an iTerm window from the command line?

  9. 9

    How do I pass a username to an FTP command from the command line?

  10. 10

    how to push to git from Terminal / Command Line

  11. 11

    How detach repl from starting terminal/thread?

  12. 12

    How to remotely detach a screen from another terminal

  13. 13

    How do I force detach Screen from another SSH session?

  14. 14

    How to launch gedit from terminal and detach it (just like "subl" command works)?

  15. 15

    How do I drop a MongoDB database from the command line?

  16. 16

    How do I launch the Android emulator from the command line?

  17. 17

    How do I run a gui app from the command line?

  18. 18

    How do I read arguments from the command line with an MPI program?

  19. 19

    How do I open a file with Chrome from the command line?

  20. 20

    How do I get the default font from the command line?

  21. 21

    How do I upgrade releases from a Live USB with the command line?

  22. 22

    How do I install the latest version of cmake from the command line?

  23. 23

    How do I start the Privacy and Activity Manager from command line?

  24. 24

    How do I make pip available from command line mac?

  25. 25

    How do I build boost 1.55 from the command line with mingw?

  26. 26

    How do I control the WMP from command line/batch

  27. 27

    How do I open a WinSCP GUI session from command line?

  28. 28

    How do I add multiple "+" commands into less from the command line

  29. 29

    How do I download mail folders from command line?

HotTag

Archive