UNIX For Dummies [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

UNIX For Dummies [Electronic resources] - نسخه متنی

John Levine, Margaret Levine Young

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید






Starting Background Processes


Starting a background command is simplicity itself. You can run any program you want in the background: When you type the command, stick a space and an ampersand (& ) at the end of the line just before you press Enter.

Suppose that you want to use troff to print a file (even though we warned you not to use it). Because this process is bound to take a long time, for example, typing the ampersand to run it in the background is wise:


troff a_really_large_file &

The shell starts the command and immediately comes back to ask you for another command. It prints a number, which is the process ID (or PID) assigned to the command you just started. (Some shells print a small number, which they call the job number, and a larger number, which is the PID.) If you know the PID, you can check up on your background program with the ps command. If you get tired of waiting for the background process, you can get rid of it with the kill command and the PID, as you see in Chapter 24.

You can start as many programs simultaneously as you want in this way. In practice, you rarely want more than three or four. Because only one computer is switching back and forth among the various programs, the more simultaneous things you do, the slower each one runs.

When your background program finishes, the C, Korn, BASH, and SVR4 Bourne shells tell you that the program is finished; older versions of the Bourne shell say nothing.

Tip If you know that a program will take a long time (a program that crunches for a long time to produce a report, for example), you can use the nice command with that program. The nice command tells the program to run in a nice way so that it gets a smaller share of the computer than it would otherwise. Although the nice program takes longer to run, other programs run faster, which is usually a good trade-off if the nice program was going to take a long time anyway. To use it, you just type nice followed by the command to run:


nice genreport Tuesday.raw &

You almost always use nice to run programs in the background because only an inexplicably saintly user wants to slow down a program he was going to sit and wait for.

If you want to wait for background programs to finish, the wait command waits for you until they’re all finished. If you become impatient, you can interrupt wait by pressing Ctrl+C (or Del, depending on your system). These keystrokes interrupt only the wait and leave the background processes unmolested.

/ 213