Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Linux Timesaving Techniques For Dummies.pdf
Скачиваний:
59
Добавлен:
15.03.2015
Размер:
15.98 Mб
Скачать

280 Technique 39: Controlling Troublesome Processes at the Command Line

sound confusing if you’re not familiar with the bash command substitution feature, so it may help to break the command down a bit. Assume that the pgrep command returns three process IDs:

$ pgrep -U freddie,franklin 5523 7879 8256

bash substitutes the output from pgrep into the ps command like this:

$ ps -l --pid 5523 7879 8256

You can feed the output from pgrep into any program that expects a list of process IDs, such as kill. To kill all processes owned by user freddie, you can combine pgrep and kill like this:

$ kill $(pgrep -U freddie)

Killing Processes with pkill

An easy way to kill off unwanted processes is pkill. pkill is nearly identical to pgrep (in fact, you can select processes using the same criteria in Table 39-3, which you can find earlier in this technique) except that pkill kills the matching processes instead of displaying matching process IDs. To kill all processes owned by user freddie, use the following command:

$ pkill -U freddie

pkill (and its cousin, kill) work by sending a signal to the targeted process. By default, pkill sends the SIGTERM signal to suggest that the target process terminate itself. If you find a program that’s not willing to honor SIGTERM, you can be more forceful by using the -SIGKILL option:

$ pkill -SIGKILL -U freddie

You can send any signal with pkill. For a complete list of signals (and their meanings), see man 7 signal.

Killing Processes with killall

pkill is a bit aggressive, and if you’re not careful, it can kill processes that you don’t intend to harm. If you want to kill a collection of processes, exercise some caution and use killall instead.

killall isn’t as flexible as pkill when it comes to selecting processes, but it has one very nice feature: interactive mode. killall selects processes based on program name. When you run killall, use the --interactive option (or -i for short) to tell killall to prompt you before it kills each process:

$ pgrep -lf more

10512 more mozilla/run-mozilla.sh

10513 more /etc/passwd

$ killall --interactive more Kill more(10512) ? (y/n) y Kill more(10513) ? (y/n) n

Like pkill, killall sends SIGTERM by default. If you want to send a different signal, use the --signal signal-name option:

$ killall -i --signal SIGKILL more Kill more(10512) ? (y/n) y

Kill more(10513) ? (y/n) n

Closing Windows with xkill

Once in a while, a window appears on your desktop, and you just don’t know where it came from. It might be a pop-up ad from a piece of spyware, an annoying message from a program running in the background, or just a program that forgot to identify itself. If you don’t know the name of the program that created the window, you can’t kill it with kill, pkill, or killall. You need xkill, which kills off a program when you click the program’s window. To see xkill in action:

Getting Your Processes’ Priorities Straight

281

1. Start up a copy of xmms and tell it to play a media stream (see www.shoutcast.com if you’re looking for some good music).

2. Now, open a terminal window and run the following command:

$ xkill

Select the window whose client you wish to kill with button 1....

Notice that the mouse cursor has changed from its familiar arrow to something that looks like a target sight in an F-16.

3. Click anywhere on the xmms window, and the media player is killed.

Be careful with xkill — you can easily kill off the wrong program with a single click. xkill will kill just about any window that you click — even the KDE (or GNOME) taskbar!

Make sure that the window you want to kill is visible. You can’t move to a different desktop by clicking the pager (the multiple-desktop control down on your taskbar) because you’ll kill the pager instead.

If you change your mind after you start xkill, just right-click anywhere on the screen, and xkill will end without doing any damage.

xkill isn’t foolproof. It can’t kill every program, but we’ve yet to find one that it can’t handle. Of course, you need the right privileges to use xkill. You can kill off processes that you own, but you can’t kill processes owned by other users.

If you need to kill a process owned by another user, give yourself superuser privileges (with su) before you run xkill.

Getting Your Processes’

Priorities Straight

Linux uses a relatively simple scheme for divvying up available CPU time. CPU time is divided into short segments, and each period is called a quantum. As each quantum expires, the kernel chooses a new process to run from the list of processes with the highest priorities. Each process is assigned a priority that can change over time. The base priority assigned to a process is known as its nice value.

The name is a little strange and so is the numbering scheme. Nice values range from +20 (lowest priority) to –20 (highest priority), and most processes start with a nice value of 0. Think of it this way: A program with a high nice value is being nice to other processes by giving up the CPU when someone else needs it.

To view the nice value of an existing process, use this command:

$ ps -l process-id

You can lower the priority (that is, increase the nice value) of your own processes by using the renice command. For example, here’s how to lower the priority of your bash shell:

$ renice +10 $$

6297: old priority 0, new priority 10

(The $$ shell variable contains the process ID of your shell.)

If you have superuser privileges, you can increase or decrease the nice value of any process. You can identify processes by process ID (-p pid), process group (-g process-group), or user name (-u user).

You can also use KDE System Guard to renice programs in a graphical environment. Check out Technique 41 for help using KDE System Guard.

40 Taking Care of New

(And Old) Users

Technique

Save Time By

Using the Fedora/ Mandrake user manager to add users and groups

Forcing users to update passwords

Changing passwords with a few clicks

Organizing your users into groups

Using filters to find users fast

Even if you’re the only user on your system, you likely already know that you need at least two user accounts: you and your alter ego — the superuser. Your wild side (the superuser) is there when you

need it to customize configuration files, install software, and remove old files. Your more sensible identity is for moving with speed and agility, without the danger of accidentally wiping out the contents of your online world with a typing error.

If you manage a system with multiple users, or you manage a network, you’ve likely set up each user with his or her own identity so you don’t have roots running around willy-nilly changing passwords and uninstalling packages.

Whether you manage two user accounts or 200, the graphical user manager that comes with your distribution is the timesaving way to manage them. This tool simplifies account-related tasks, letting you avoid command line interaction. You don’t have to remember any commands; just point and click to create and manage users and their information. The process of adding new users and modifying existing ones is fast.

Using groups to organize file privileges can save you a ton of time. The graphical user manager makes it easy to create and populate groups with its handy checklist. Fedora Linux and Mandrake Linux (currently) use the same user manager tool. As we describe the Fedora user manager, just remember that everything that we tell you applies to the Mandrake user manager as well.

In this technique, we introduce you to the advantages of your distribution’s user manager. You’ll save time (and a lot of typing) by using this simple tool to keep your user accounts and groups up-to-date. Every file and program on a Linux computer is owned by a single user and a single group. Every file (and program) also has a set of permissions that determine what the owner can do to the file, what members of the group can do, and what everyone else can do.

To make the system a safer place, assign each user a unique user name and password. When you create a separate account for each user, it has the following effects:

Соседние файлы в предмете Операционные системы