Jay Taylor's notes
back to listing indexHow do I detach a process from Terminal, entirely?
[web search]
I use Tilda (drop-down terminal) on Ubuntu as my "command central" - pretty much the way others might use GNOME Do, Quicksilver or Launchy. However, I'm struggling with how to completely detach a process (e.g. Firefox) from the terminal it's been launched from - i.e. prevent that such a (non-)child process
For example, in order to start Vim in a "proper" terminal window, I have tried a simple script like the following:
However, that still causes pollution (also, passing a file name doesn't seem to work).
|
|||||||||||||||||||||||||||
migrated from stackoverflow.com Aug 21 '10 at 4:05This question came from our site for professional and enthusiast programmers. |
|||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||
First of all; once you've started a process, you can background it by first stopping it (hit Ctrl-Z) and then typing You can start a process as backgrounded immediately by appending a "&" to the end of it:
To run it in the background silenced, use this:
Some additional info:
What you can't do, is change the stdout/stderr/stdin of a process after having launched it. At least not from the shell. If you launch your process and tell it that its stdout is your terminal (which is what you do by default), then that process is configured to output to your terminal. Your shell has no business with the processes' FD setup, that's purely something the process itself manages. The process itself can decide whether to close its stdout/stderr/stdin or not, but you can't use your shell to force it to do so. To manage a background process' output, you have plenty of options from scripts, "nohup" probably being the first to come to mind. But for interactive processes you start but forgot to silence ( I recommend you get GNU Oh, and by the way, don't use "
That's probably not what you want because -e only takes one argument. Use It's really difficult to get multiple arguments working properly in the scenario that you gave (with the
|
|||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||
|
If you are using Another approach you can try is |
|||||||||||||||||||||||||||||||||
|
Reading these answers, I was under the initial impression that issuing In my case,
or
if you prefer one-liners. This has the generally desirable effect of removing the subprocess from the jobs table. This allows you to exit the terminal emulator without accidentally signaling the child process at all. No matter what the After the disown, the process is still a child of your terminal emulator (play with What to do if your shell does not support
|
|||
I think screen might solve your problem
|
|||
I've been using number 2 for a very long time, but number 3 works just as well. Also, disown has a 'nohup' flag of '-h', can disown all processes with '-a', and can disown all running processes with '-ar'. Silencing is accomplished by '$COMMAND &>/dev/null'. Hope this helps! |
|||||||||
|
in tcsh (and maybe in other shells as well), you can use parentheses to detach the process. Compare this:
To this:
This removes firefox from the jobs listing, but it is still tied to the terminal; if you logged in to this node via 'ssh', trying to log out will still hang the ssh process. |
||||
You can run your command using the nohup command, this detach your process and redirects outputs to a given file... but I am not sure that is exactly what you need .. |
|||||||||
|
To disassociate tty shell run command through sub-shell for e.g. (command)& When exit used terminal closed but process is still alive. check -
Open other terminal
Process is still alive. |
|||||||||
|
Backgrounding and foregrounding a job is probably one of the very first things every Unix sys-admin should know. Here is how it is done:
|
||||
Try daemon -- should be available from your friendly package manager and comprehensively take care of every way of disassociating itself from the terminal. |
|||
In my .bashrc, I have these functions for precisely that purpose:
Prefix a command with The function is written to work with |
|||||||||||||||
|
I use the following script to do this. It stops the process printing to the terminal, detaches with
Usage example:
|
|||
I have found on Mac OS X that I need to use both nohup AND disown to ensure that the child process is not torn down with the terminal. |
|||
Your Answer
asked |
7 years ago |
viewed |
187174 times |
active |
Linked
Related
Hot Network Questions
- Is there a word in Esperanto for "lightsaber"?
- When stating a theorem in textbook, use the word "For all" or "Let"?
- How to challenge optimized player with Sharpshooter feat
- How to say “let's” in Portuguese?
- A riddle in James Still's "River of Earth"
- How do I input n repetitions of a digit in bash, interactively
- Find the limit of the following expression:
- Why don't you connect unused hot and neutral wires to "complete the circuit"?
- Can Communism become a stable economic strategy? How?
- How to use \char inside \pdfinfo?
- Should ideal specular multiply light colour with material colour?
- Looking for a term like "fundamentalism", but without a religious connotation
- Is it a fallacy, and if so which, to believe we are special because our existence on Earth seems improbable?
- What would be a good approach to make sure advisor goes through all the report?
- Is stack unwinding with exceptions guaranteed by c++ standard?
- Why I failed to use the \foreach command to connect the points?
- Problems with "+" in grep
- Why was Gilderoy Lockhart unable to be cured?
- Inserting a DBNull value into a database
- Asking client for discount on tickets to amusement park
- Is it plagiarims (or bad practice) to cite reviews instead of source material?
- Draw an ASCII chess board!
- TreePlot does not give a "binary-looking" tree for a binary tree
- What happens if anti-refelctive coating is fully ruined or removed from lens most outer surface?
Technology | Life / Arts | Culture / Recreation | Science | Other | ||||||
---|---|---|---|---|---|---|---|---|---|---|