views:

705

answers:

3

I yesterday upgraded by MacPorts' apps which took apparently about 4 hours. It was irritating to see the installation process going on in one tab in terminal.

Problem: to hide a running process in terminalsuch that it does not take space in my working area

I found today that there a new command coproc in Bash 4:

coprocess is executed asynchronously in a subshell, as if the command established between the executing shell and the coprocess

I am not sure whether you can use it to solve the problem or not. I did not manage to use it.

How can you hide the running process such that it is not visible in terminal but it continues to run?

+4  A: 

Did you consider Ctrl + Z to put the process in pause, then bg to run this one in background?

To detach your process from the terminal, you can then type disown. You can now close the terminal, and even your session.

The problem here is that the outputs will appear anyway in the bash.

You can also start your program in screen. This command provide an easy way to start a program, close the console and retrieve it later.

Jérôme
Let's assume I press Ctrl-Z and I am running an installation process by MacPorts. Can it cause some conflicts if I pause the process and start again?
Masi
Nice, but I would also suggest 'disown' after 'bg' and then you can close the terminal with (probably) no problems.
Josh K
@Masi: As you pause the entire process, it can not cause any conflict. It is like a very long process switch. @Josh: Thank you, I didn't know disown! It is a lot simpler than with screen to not depend on a terminal!
Jérôme
@Jérôme: Be aware that disowning is a one way street. They is no way to reattach as with screen.
dmckee
Thank you for your answers!
Masi
+2  A: 

I suspect you are looking for nohup

nohup LongRunningNoisyProgram &

will run the program, log the output to a file so you don't see it, push the program into the background, and won't cancel the program if you exit your terminal later while it is still running.

McBeth
Nohup is a good tool, but no help if you discover the problem *after* you start it...
dmckee
Masi
Does Firefox use the command if you start it from terminal? It must have some output in terminal when you use it. It apparently hides these pieces of information from the user.
Masi
R. Bemrose
The problem with disown is that it is bash specific. Mac switched to BASH a while back, so the OP is okay using disown (and never see the output). On Sun, nohup has a command line switch that lets you apply nohup to a running process (or jobID). @Masi, firefox will spam your terminal if you start it from there.I'm a huge fan of screen, and run most of my day-to-day desktop activities in one, but screen definitely has to happen before you start. I do most of my hobby programming in screen, using it to split my terminal with vi in the top and a command line on the bottom.
McBeth
Thank you for your answers!
Masi
A: 

There is at least one thing the other repliers have not covered: how to manage hiding processes.

Suppose you have 100 background processes created with "nohup find / &". You want to quit them to really see how the background processes work. Please, use the command:

ps -ej | awk '! /grep/ && /find/ {print $2}' | xargs kill -9

Then, you may want to know how to control the keys to hide processes. You can change it to p, where susp stands for CTRL+z (^Z):

stty susp p

You can see the keys here:

stty -a

Please, compare the stdouts before and after the change. The command is particularly useful because it helps to remember other commands, such as ^W (to remove a word).

Jerome had an excellent tip about screen. I highly recommend to pursue the direction:

http://www.commandlinefu.com/commands/matching/screen/c2NyZWVu/sort-by-votes

Masi