[英]kill function returning invalid argument
I am using kill
function to kill
a process. 我正在使用
kill
函数来kill
一个进程。 However, its returning -1 and perror
shows "Invalid argument". 但是,其返回-1和
perror
显示“无效参数”。 Reading the manual of kill
, it says this error occurs if wrong signal value is provided. 阅读
kill
手册,它说如果提供了错误的信号值,则会发生此错误。 I am passing -9
or SIGKILL
, like this kill( SIGKILL, pid )
. 我正在传递
-9
或SIGKILL
,就像这个kill( SIGKILL, pid )
。
Then why is it giving invalid argument error. 那为什么会给出无效的参数错误呢? Note that the process who is calling the
kill
function is the child of the process that we are trying to kill. 请注意,正在调用
kill
函数的进程是我们试图杀死的进程的子进程。
kill
takes its arguments the other way around. kill
则相反。 From the man page : 从手册页 :
int kill(pid_t pid, int sig);
Since you're passing the PID in place of the signal number and vice-versa, it's pretty likely that at least one of them will be an invalid argument as perror
is telling you. 由于您要通过传递PID来代替信号编号,反之亦然,因此很可能至少有一个参数是无效的参数,因为
perror
正在告诉您。
Your kill( SIGKILL, pid );
你的
kill( SIGKILL, pid );
should be kill(pid, SIGKILL);
应该是
kill(pid, SIGKILL);
man 2 kill
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.