回复:unix下居然有用kill -9杀不死的进程

来源: westmont 2014-04-18 05:39:14 [] [旧帖] [给我悄悄话] 本文已被阅读: 次 (2696 bytes)

In Unix, why can't I kill certain background processes even with kill -9?

Occasionally you will have a process in Unix that you want to kill but cannot. This generally happens with SUID (Set User ID) processes, which are programs that assume (or allow assumption of, depending on particulars of the operating system) the file owner's UID when started. (Technically, the process's "effective" UID is set. The "real" UID is always yours.)

As soon as you run such a program, you no longer own the process. Many network-based applications run this way to take advantage of direct device access. This assumes that the user programs which have been SUID'd will behave properly and are written in a secure fashion.

Occasionally you will run into a situation where the SUID process does not behave properly. To kill a process like this, you must regain interactive control of the process or kill the parent process of the hung process.

To regain control of a backgrounded process, you need to bring the jobs it is associated with into the foreground. List the jobs you have running by entering the jobs command at your prompt:

jobs

You should see output similar to this:

[1]+ Stopped emacs19

[2]- Running ping -l deathstar

To regain control of the ping command use the fg command:

fg %x

Replace x with the number of the job in the listing. Often, you will not need to include the % (percent sign).

Once you have regained terminal control of the process, send an interrupt to the process by pressing Ctrl-c . This should stop the process and return you to the shell. If it does not, try sending a quit signal to the process by pressing Ctrl-\ (backslash).

Note: Some programs, such as Pine and Emacs, will not respond to either of these signals, but typically have their own commands to stop their processes.

If neither of these control key sequences work, try stopping the process by killing its parent process. On System V implementations, which include all UITS central systems, you can list your processes with parent process IDs included by entering:

ps -fu username

Replace username with your username. The equivalent BSD command is:

ps xl

This will list all of your processes and their process IDs (PID in the listing) and parent process IDs (PPID in the listing). Locate the original process you are trying to kill, and send a HUP (Hangup) signal to it. Do this by entering:

kill -HUP <PPID>

Replace <PPID> with the parent process ID.

请您先登陆,再发跟帖!