1.写一个C++程序,监控另一个进程,发现该进程关掉了就自动把它重启。
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
using namespace std;
int _tmain(int argc, TCHAR *argv[])
{
STARTUPINFO si;
PROCESS_INFORMATION pi; //进程信息:
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
do{
// 创建子进程,判断是否执行成功
if(!CreateProcess( NULL,"cmd /c d:\\1.jpg",NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
{
cout << "创建进程失败.." << GetLastError() << endl;
system("pause"); //用于测试
return 0;
}
//进程执行成功,打印进程信息
cout << "以下是子进程的信息:" << endl;
cout << "进程ID pi.dwProcessID: " << pi.dwProcessId << endl;
cout << "线程ID pi.dwThreadID : " << pi.dwThreadId << endl;
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载
- 1
- 2
- 3
- 4
- 5
- 6
前往页