Skip Navigation

Running programs in the background

“This will take forever to run!”

If you find yourself saying that about a program, chances are that you’ll need to run it just a little bit differently. Here’s how:

  1. Don’t run it on prism! People depend on prism being up and running, and when several people (or even just one) are running large programs, then it slows everybody else down. Running a program that takes less then ten minutes is okay, but running a longer program is impolite. And when you think your program is done, type top at the command prompt and make sure it’s not still running.
  2. Don’t leave yourself logged in! Unless you’re willing to sit right there and baby-sit that computer, that is. Leaving a computer logged-in when you aren’t there to guard it is a dangerous idea. Malicious hackers sit and wait to take advantage of innocents like you.
  3. Don’t lock your screen and leave! Locking your screen is a relatively easy way to protect your account, and is very useful in many situations. However, some people have no compunction about restarting a locked computer. If you have a program running, you’ll lose it. And locking a computer means no one else can use it, which is silly and anti-social.

Gee, so what can I do?

  1. Background the process. If the name of your program is myprog, then just type myprog & at the command line. That makes your program run in the background. From here you can either log out or lock the screen. (Be sure to leave a note so that no one restarts the computer!)
  2. Be nice. When you type nice myprog & at the command line, that means that although your program gets most of the CPU time when no one’s doing anything else, it won’t hog the CPU time when someone else tries to use Mozilla. If you background your process, the nice command insures that other people can still accomplish things too.
  3. Use screen. Backgrounding the process is fine if your output is being written to a file. However, if you background a process and then log out, you can’t foreground it again (“man fg” for more info). And that means that you won’t see any output.

If you need to see the output of your program, or if you occasionally need to talk to it, use screen instead by typing screen at the command prompt. You will be given a new command prompt, where you type myprog. Now your program will run in the screen window. To get back to your terminal window, type ^a d (that is, type “Ctrl and a” at the same time, and then type “d”). From here you can log out, or lock your screen, or do whatever. To get back to your program (even if you’ve logged out and then logged back in!), type screen –r at the terminal window command prompt. Like backgrounding, this only works if no one reboots or turns off the computer, so be sure to leave a note!