Linux下使用C杀死进程.

#include
#include
#include
#include
#include 
void main(int argc,char *argv[])
{
	int num;
	num=atoi(argv[1]);
	int status;
	status=kill(num,SIGKILL);
	if (status == -1)
		printf("kill faild\n");
	wait(&status);
	if(WIFSIGNALED(status))
		printf("chile process receive signal %d\n",WTERMSIG(status));
}
#include
#include

void main(int arg,char* args[])
{
	int pid = atoi(args[1]);
	DWORD p = (DWORD)pid;
	if (KillProcess(pid))
		printf("OK");
}

BOOL KillProcess(DWORD ProcessId)
{
	HANDLE hProcess=OpenProcess(PROCESS_TERMINATE,FALSE,ProcessId);
	if(hProcess==NULL)
		return FALSE;
	if(!TerminateProcess(hProcess,0))
		return FALSE;
	return TRUE;
}


你可能感兴趣的:(C,Language)