Windows system call Process terminated

Source: Internet
Author: User

1#include"windows.h"2#include"iostream"3#include"stdio.h"4 using namespacestd;5 6 StaticLPCTSTR q_szmutexname="W2KDG. ProcTerm.mutex.Suicide";7 8 HANDLE Startclone () {9 TCHAR Szfilename[max_path];Ten GetModuleFileName (null,szfilename,max_path); One  A TCHAR Szcmdline[max_path]; -sprintf_s (szCmdLine, "\"%s\ "\" child\ "", szFileName); -  the startupinfo si; -  -ZeroMemory (reinterpret_cast<void*> (&si),sizeof(SI)); -si.cb=sizeof(SI); + process_information Pi; -  +BOOL bcreateok=CreateProcess ( A szFileName, at szCmdLine, - NULL, - NULL, - FALSE, - Create_new_console, - NULL, in NULL, -&Si, to&Pi +         ); -  the     if(bcreateok) { * CloseHandle (pi.hprocess); $ CloseHandle (pi.hthread);Panax Notoginseng         returnpi.hprocess; -     } the  +     Else returnInvalid_handle_value; A } the  + voidParent () { -cout<<"Creating The child process and waited child process to quit."<<Endl; $HANDLE hchild=Startclone (); $     if(hchild!=Invalid_handle_value) -     { - WaitForSingleObject (hchild,infinite); thecout<<"The child process had quited."<<Endl; - Wuyi     } the  -     Else  Wucout<<"Create child process failed."<<Endl; - } About  $  - voidChild () { -cout<<"Child ID quiting"<<Endl; -Sleep ( the); A  + } the  - intMainintargcChar*argv[]) { $     if(argc>1&AMP;&AMP;STRCMP (argv[1]," Child")==0){ the Child (); the     } the     Else{ the Parent (); -     } in     return 0; the  the}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.