简体   繁体   English

终止函数返回无效参数

[英]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 ) . 我正在传递-9SIGKILL ,就像这个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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM