Running Commands in the Background or in Virtual Consoles

When using MS-DOS, you have no choice but to wait for each command to complete before you enter the next command. (You can type ahead a bit, but the MS-DOS system can hold only a few characters in its internal buffer.) Linux, however, can handle multiple tasks simultaneously. The only problem you may have is that the terminal or console is tied up until a command completes.

If you work in a terminal window and a command takes too long to complete, you can open another terminal window and continue to enter other commands. If you work in text mode, however, and a command seems to take too long, you need some other way to access your system.

Several methods enable you to continue working while your Linux system handles a lengthy task:

♦ You can start a lengthy command in the background, which means that the shell starts the process corresponding to a command and immediately returns to accept more commands. The shell does not wait for the command to complete; the command runs as a distinct process in the background. To start a process in the background, simply place an ampersand (&) at the end of a command line. When I want to run the convpcx shell script to convert an image file named imagel to PCX format, for example, I run the script in the background by using the following command:

convpcx imagel &

♦ If you want a command to continue running in the background after you log out, use nohup to start the command using the following syntax:

nohup command

This causes the command to run in the background and all output is redirected to a file named nohup.out.

♦ If a command (that you have not run in the background) seems to be taking a long time, press Ctrl-Z to stop it; then type bg to put that process in the background.

♦ Use the virtual-console feature of Linux. Even though your Linux system has only one physical terminal or console (the combination of monitor and keyboard is called the terminal or console), it gives you the appearance of having multiple consoles. The initial text screen is the first virtual console. Press Alt-F2 to get to the second virtual console, Alt-F3 for the third virtual console, and so on. From the GUI desktop, you have to press Ctrl-Alt-F1 to get to the first virtual console, Ctrl-Alt-F2 for the second one, and so on.

insider To get back to the GUI desktop, press Ctrl-Alt-F7. You can use one of the virtual con-insight soles to log in and kill processes that may be causing your X display screen to become unresponsive (for instance, if the mouse stops responding).

Was this article helpful?

0 0
Make Money Writing

Make Money Writing

This Report Will Show You How To Make Money By Providing Writing Services To Other Internet Marketers. Learn how to make money by writing the right way. Grab your copy of this report now and learn. Why writing is a great way to earn money. How to compete with cheap writers, even if you charge a lot more money.

Get My Free Ebook

Post a comment