Thursday, April 27, 2006

Shell tip:Bring background processes to the foreground

This is something that most people using linux may have known. Though I have been using linux for a long time now, I did not know how to bring a particular process running in the background (using the & option) to the foreground after I have many background processes running. Let me illustrate this with an example. Let us run two processes in the background and see how we can bring either of them to the foreground.

> top &

> emacs &

Now typing "jobs" will inform you of the bacground processes

>jobs
[1] + Suspended (tty output) top
[2] - Running emacs

It can be observed that each process has a unique id on the left. That can be used to bring the process to the foreground.

> fg %1

will bring "top" to the foreground.


This is something I learnt today and may be helpful to you too, IMHO.

1 comment:

Unknown said...

Lose the fg and give only the number with the percent sign and it will still work.

So, instead of fg %1, you can simply give %1 or %2 in the prompt to bring it foreground.