LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1639|回复: 12

kill 问题

[复制链接]
发表于 2004-7-28 08:31:54 | 显示全部楼层 |阅读模式
kill -0 pid 其中-O是什么意思?
man kill
0      All processes in the current process group are signaled.

还是看的不是很明白。说得是当前进程组中所有的进程都被signaled。可是这个signal是什么呢?
是试了一下,并没有杀死进程,那么有什么作用呢?
谢谢!
发表于 2004-7-28 11:56:03 | 显示全部楼层
杀死进程直接用
kill -9 pid
signal是信号的意思
发表于 2004-7-29 03:23:33 | 显示全部楼层
Unix/Linux 系统信号表:
[PHP]
#define SIGHUP     1    /* hangup, generated when terminal disconnects */
#define SIGINT     2    /* interrupt, generated from terminal special char */
#define SIGQUIT    3    /* (*) quit, generated from terminal special char */
#define SIGILL     4    /* (*) illegal instruction (not reset when caught)*/
#define SIGTRAP    5    /* (*) trace trap (not reset when caught) */
#define SIGABRT    6    /* (*) abort process */
#define SIGEMT     7    /* EMT intruction */
#define SIGFPE     8    /* (*) floating point exception */
#define SIGKILL    9    /* kill (cannot be caught or ignored) */
#define SIGBUS    10    /* (*) bus error (specification exception) */
#define SIGSEGV   11    /* (*) segmentation violation */
#define SIGSYS    12    /* (*) bad argument to system call */
#define SIGPIPE   13    /* write on a pipe with no one to read it */
#define SIGALRM   14    /* alarm clock timeout */
#define SIGTERM   15    /* software termination signal */
#define SIGURG    16    /* (+) urgent contition on I/O channel */
#define SIGSTOP   17    /* (@) stop (cannot be caught or ignored) */
#define SIGTSTP   18    /* (@) interactive stop */
#define SIGCONT   19    /* (!) continue (cannot be caught or ignored) */
#define SIGCHLD   20    /* (+) sent to parent on child stop or exit */
#define SIGTTIN   21    /* (@) background read attempted from control terminal*/
#define SIGTTOU   22    /* (@) background write attempted to control terminal */
#define SIGIO     23    /* (+) I/O possible, or completed */
#define SIGXCPU   24    /* cpu time limit exceeded (see setrlimit()) */
#define SIGXFSZ   25    /* file size limit exceeded (see setrlimit()) */
#define SIGMSG    27    /* input data is in the ring buffer */
#define SIGWINCH  28    /* (+) window size changed */
#define SIGPWR    29    /* (+) power-fail restart */
#define SIGUSR1   30    /* user defined signal 1 */
#define SIGUSR2   31    /* user defined signal 2 */
#define SIGPROF   32    /* profiling time alarm (see setitimer) */
#define SIGDANGER 33    /* system crash imminent; free up some page space */
#define SIGVTALRM 34    /* virtual time alarm (see setitimer) */
#define SIGMIGRATE 35   /* migrate process */
#define SIGPRE    36    /* programming exception */
#define SIGVIRT   37    /* AIX virtual time alarm */
#define SIGALRM1  38    /* m:n condition variables - RESERVED - DON'T USE */
#define SIGWAITING 39   /* m:n scheduling - RESERVED - DON'T USE */
#define SIGRECONFIG 58  /* Reserved for Dynamic Reconfiguration Operations */
#define SIGCPUFAIL 59   /* Predictive De-configuration of Processors - */
                        /*      RESERVED - DON'T USE */
#define SIGKAP    60    /* keep alive poll from native keyboard */
#define SIGGRANT  SIGKAP /* monitor mode granted */
#define SIGRETRACT 61   /* monitor mode should be relinguished */
#define SIGSOUND  62    /* sound control has completed */
#define SIGSAK    63    /* secure attention key */
/*
* additional signal names supplied for compatibility, only
*/
#define SIGIOINT SIGURG /* printer to backend error signal */
#define SIGAIO  SIGIO   /* base lan i/o */
#define SIGPTY  SIGIO   /* pty i/o */
#define SIGIOT  SIGABRT /* abort (terminate) process */
#define SIGCLD  SIGCHLD /* old death of child signal */
#define SIGLOST SIGIOT  /* old BSD signal ?? */
[/PHP]
 楼主| 发表于 2004-7-29 08:42:37 | 显示全部楼层
谢谢楼上的各位,我并不是想杀死进程的,而是看到一个脚本中有kill -0 不知道“-0”这个参数是什么作用,向目标进程发送什么样的信号。
谢谢!
发表于 2004-7-29 09:55:50 | 显示全部楼层
All processes in the current process group are signaled
向该进程组的所有进程发送一个信号
kill -O 进程组id
没有指定信号就是发送SIGTERM
(请参阅有关进程组的资料)
 楼主| 发表于 2004-7-29 15:19:04 | 显示全部楼层
可是我试了,kill -0 pid不能杀死该进程的。不信可以试试看。按照楼上的老兄的话,是SIGTERM应该试可以杀死的了。所以很是奇怪
发表于 2004-7-29 15:29:13 | 显示全部楼层
SIGTERM的信号是多少?!
发表于 2004-7-30 10:00:30 | 显示全部楼层
呵呵,不好意思,我没man kill看看就望文生义了

kill [ -s signal | -p ] [ -a ] [ -- ] pid ...
pid可以是n, 0, -n, -1并且
-n     where n is larger than 1.  All processes in process group
        n are signaled...
这样看来
kill -0 pid 语法上表示向-0和pid发送信号
其中-0应该无意义
没有杀掉pid可能因为pid所指的进程乎略TERM信号
试试kill -9 pid看看?

不知解释的对否,请牛人继续...
 楼主| 发表于 2004-7-30 11:29:01 | 显示全部楼层
-0一定是有意义的,因为我试过同样一个httpd进程用kill pid就可以杀掉,这个说应该是没有忽略SIGTERM信号的。可是用kill -0 pid就杀不掉。那么-0到底是不是SIGTERM信号呢?
 楼主| 发表于 2004-7-30 11:30:08 | 显示全部楼层
关键代码如下。
是apache自带的启动脚本

  1. ERROR=0
  2. ARGV="$@"
  3. if [ "x$ARGV" = "x" ] ; then
  4.     ARGS="help"
  5. fi  

  6. for ARG in $@ $ARGS
  7. do  
  8.     # check for pidfile
  9.     if [ -f $PIDFILE ] ; then
  10.         PID=`cat $PIDFILE`
  11.        [color=crimson] if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ;[/color] then
  12.             STATUS="httpd (pid $PID) running"
  13.             RUNNING=1
  14.         else
  15.             STATUS="httpd (pid $PID?) not running"
  16.             RUNNING=0
  17.         fi
  18.     else
  19.         STATUS="httpd (no pid file) not running"
  20.         RUNNING=0
  21.     fi

  22.     case $ARG in
  23.     start)
  24.         if [ $RUNNING -eq 1 ]; then
  25.             echo "$0 $ARG: httpd (pid $PID) already running"
  26.             continue
  27.         fi
  28.         if $HTTPD ; then
  29.             echo "$0 $ARG: httpd started"
  30.         else
  31.             echo "$0 $ARG: httpd could not be started"
  32.             ERROR=3
  33.         fi
  34.         ;;
  35.     stop)
  36.         if [ $RUNNING -eq 0 ]; then
  37.             echo "$0 $ARG: $STATUS"
  38.             continue
  39.         fi
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表