网络技术是从1990年代中期发展起来的新技术,它把互联网上分散的资源融为有机整体,实现资源的全面共享和有机协作,使人们能够透明地使用资源的整体能力并按需获取信息。资源包括高性能计算机、存储资源、数据资源、信息资源、知识资源、专家资源、大型数据库、网络、传感器等。 当前的互联网只限于信息共享,网络则被认为是互联网发展的第三阶段。 刚刚学内核对象,想写个可以防杀的进程,但其他方法太高级,本菜鸟不感高攀,想了几天,想到一个很本的办法,不正确的 方还请高手指点一下. 程序运行两个事例,每个实例互相监视另外的实例是否存在, 如果不存在,就运行一个. 代码: // test_process.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "tchar.h" #include "iostream.h" #include "windows.h" LPCTSTR lpszMutex1 = _T("mutex1"); LPCTSTR lpszMutex2 = _T("mutex2"); DWORD WINAPI Thread1(LPARAM lParam); DWORD WINAPI Thread2(LPARAM lParam); int main(int argc, char* argv[]) { HANDLE hMutex1 = CreateMutex(NULL, FALSE, lpszMutex1); if (hMutex1 != NULL) if (GetLastError() == ERROR_ALREADY_EXISTS) { CloseHandle(hMutex1); cout << lpszMutex1 << " already exist." << endl; HANDLE hMutex2 = CreateMutex(NULL, FALSE, lpszMutex2); if (hMutex2 != NULL) if (GetLastError() == ERROR_ALREADY_EXISTS) { cout << lpszMutex2 << " already exist." << endl; return 1; } } DWORD dwThreadId; HANDLE hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)Thread1,NULL,0,&dwThreadId); CloseHandle(hThread); while (1) Sleep(1); return 0; } DWORD WINAPI Thread1(LPARAM lParam) { HANDLE hMutex; while (1) { hMutex = OpenMutex(MUTEX_ALL_ACCESS, TRUE, lpszMutex1); if (! hMutex) { STARTUPINFO si = { sizeof STARTUPINFO }; PROCESS_INFORMATION pi; TCHAR szBuf[MAX_PATH]; GetModuleFileName(GetModuleHandle(NULL), szBuf, MAX_PATH); CreateProcess(szBuf, NULL, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi); CloseHandle(pi.hThread); CloseHandle(pi.hProcess); } CloseHandle(hMutex); hMutex = OpenMutex(MUTEX_ALL_ACCESS, TRUE, lpszMutex2); if (! hMutex) { cout << "mutex 2 created." << endl; STARTUPINFO si = { sizeof STARTUPINFO }; PROCESS_INFORMATION pi; TCHAR szBuf[MAX_PATH]; GetModuleFileName(GetModuleHandle(NULL), szBuf, MAX_PATH); CreateProcess(szBuf, NULL, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi); CloseHandle(pi.hThread); CloseHandle(pi.hProcess); } CloseHandle(hMutex); cout << "Thread ..." << endl; Sleep(1); } return 1; } 网络的神奇作用吸引着越来越多的用户加入其中,正因如此,网络的承受能力也面临着越来越严峻的考验―从硬件上、软件上、所用标准上......,各项技术都需要适时应势,对应发展,这正是网络迅速走向进步的催化剂。 |
温馨提示:喜欢本站的话,请收藏一下本站!