【发布时间】:2014-03-26 01:55:09
【问题描述】:
伙计们,我正在尝试通过 C++ 程序杀死进程,它正在杀死进程,但在杀死进程后没有得到所需的输出,我想要的输出是在杀死进程后显示剩余的正在运行的进程 if块,而不是显示 else 块。我改变了 if block & else block 仍然没有得到想要的输出。 代码如下:
#include<iostream>
#include<cstdlib>
#include<csignal>
using namespace std;
int main()
{
int pid,f=0;
system("ps -all");
cout<<"Enter the Process ID to kill\n";
cin>>pid;
if((kill(pid,SIGKILL))){
f=1;
}
if(f)
{
cout<<"List of processes after killing the process with PID"<<pid<<"are"<<"\n";
system("ps -l");
}
else
{
cout<<"Cant kill the process\n";
}
return 0;
}
【问题讨论】:
-
我正在开发 ubuntu 13.04
-
阅读您正在使用的函数的documentation 总是一个好主意。