I love the command line. However, most people can’t just live on the command line, GUI’s can be pretty useful :P. I find myself spawning GUI programs from the command line a lot, and here are two tips which make doing that a pleasant experience:
‘Pausing’ programs and Running them in the Background.
When you run a command, notice how the output for that command ‘takes over’ the terminal? Sometimes you want to run a GUI program in a terminal, and have it run in the background, without tying up the prompt. Here’s how to do that…
Run a program like this:
kevin@maui:~$ vlc movie.mpg
notice how you can’t type anything now, you’ve lost your prompt. Just hit ctrl-z, and the program will pause. You’ll get control of your commandline again! You program is paused though, and likely of no use paused. If you want your program to continue running in the background just type in “bg” for background. If you want your program to hijack you prompt again, run “fg” for “foreground”
kevin@maui: $ bg #Run paused program in the background kevin@maui: $ fg #Run paused program in the foreground again
Detaching GUI processes from the terminal process
One thing that bothered me for a long time is when I run a GUI program from a terminal, if you close the terminal after, the GUI closes right along behind it. Why? The GUI program is spawned as a child process of the terminal, so closing the parent process will send kill signals to all the child processes. If you want to run a GUI and have it run independently of its parent’s process, run your commands like this:
kevin@maui:~$ vlc movie.mpg & disown
Now your player stays open after closing the terminal you spawned it from! You don’t have to have one terminal instance open for every GUI you spawn now! It took me a while to learn that trick, use it to great effect 😀
There are many other things you can do to control processes from the command line, but I’ve found those two tricks the most handy when running GUI’s from the command line.