UNIX Hints & Hacks

ContentsIndex

Chapter 5: Account Management

 

Previous ChapterNext Chapter

Sections in this Chapter:

   

5.1 User Account Names

 

5.5 GECOS Field

 

5.9 User Account Startup Files

 

5.13 Finding My Display

5.2 Passwords

 

5.6 Home Directories

 

5.10 Using Aliases

 

5.14 Copy Files to Multiple Home Directories

5.3 UID

 

5.7 Shells and the Password File

 

5.11 MS-DOS Users

 

5.15 Kill an Account

5.4 Group IDs and /etc/group

 

5.8 Configuring an Account

 

5.12 Changing Shells

 

5.16 Nulling the Root Password Without vi

 

5.15 Kill an Account

5.15.1 Description

5.15.1 Description

Use one of these examples when your system is hung and you really need to find a way to kill yourself off.

Example One: Killing Yourself Quickly

Flavors: AT&T, BSD

Shells: All

Syntax:

kill [-num] [PID]

The quickest way to kill yourself is to kill the init daemon; this is quick and not too painful.

% kill -9 -1

This can also be used to kill off other users if you are able to get into their systems. Sometimes when a system hangs it can take the network interface with it, leaving you no way to get in over the network to support the user. If you are able to get in, you can use the same technique on a user that you used for killing yourself.

# su - krice -c 'kill -9 -1'

Example Two: Killing X

Flavor: AT&T

Shells: All

Syntax:

kill [-num] [PID]

In many cases, killing X kicks you back out to a login prompt. To kill the X session, loop throughout the process table until all the related files dealing with X are killed off. Here is the ugly one-liner that finishes the job:

% for PID in `ps -u$USER | grep "fv[wm]" | awk '{print $1}'`; do kill -9 $PID; done

The command searches for the window manager for the current user in the process table, then processes through the PIDs that it found and kills them off. The command can be scripted in the following form:

% vi killx
#!/bin/sh
for PID in `ps -u$USER | grep "fv[wm]" | awk '{print $1}'`; do
    kill -9 -$PID
done

Line 1: Define the shell.

Line 2: Process the PIDs of the window manager from the user that is running the script.

Line 3: Kill the PIDS one-by-one.

Line 4: Continue processing: go to line 2.

The brackets ([]) conceal the grep command from the ps. If they weren't there, the kill command would kill itself before it had a chance to do anything. As you can see, the scripts looks for the fvwm's process, which is the window manager on this particular flavor. The pattern in the grep can be rewritten as needed for the window manager that you are using, such as Motif ( mwm) or Open Look ( olwm).

Reason

Sometimes the inevitable happens: your terminal is completely hung and your keyboard locks up. You have no choice but to kill yourself (in the UNIX sense of the word, of course!).

Real World Experience

"It was the best of times; it was the worst of times." It was the time Netscape released its browser to the UNIX world. My phone rang; a loyal user wanted to know why his unsupported beta copy of Netscape that was two weeks old was killing his entire session consistently every ten minutes. At first I thought it was because of beta problems, but 42 other users were running the same copy on the same platform without any problems. It made no sense to me. The next day one of my power users saw me struggling trying to figure out the problem with Netscape (because the system checked out). When he asked what was up, I told him the whole tragic Netscape story. His mouth dropped open with guilt after hearing the amount of time I spent on the problem. He then told me that there was a process running that monitored how long this user was on Netscape because he wasn't doing any work. When he exceeded ten minutes the process would kill his X session with a script similar to those in the preceding examples. I couldn't see the process because it ran on a remote system. It would appear for a millisecond on local machines, then drop out. From that I learned that many practical jokes were consistently being played, and I went to them first when really bizarre problems developed.

UNIX Hints & Hacks

ContentsIndex

Chapter 5: Account Management

 

Previous ChapterNext Chapter

Sections in this Chapter:

   

5.1 User Account Names

 

5.5 GECOS Field

 

5.9 User Account Startup Files

 

5.13 Finding My Display

5.2 Passwords

 

5.6 Home Directories

 

5.10 Using Aliases

 

5.14 Copy Files to Multiple Home Directories

5.3 UID

 

5.7 Shells and the Password File

 

5.11 MS-DOS Users

 

5.15 Kill an Account

5.4 Group IDs and /etc/group

 

5.8 Configuring an Account

 

5.12 Changing Shells

 

5.16 Nulling the Root Password Without vi

 

© Copyright Macmillan USA. All rights reserved.