Skip to content

Instantly share code, notes, and snippets.

@pineoc
Last active December 27, 2015 10:49
Show Gist options
  • Save pineoc/7313668 to your computer and use it in GitHub Desktop.
Save pineoc/7313668 to your computer and use it in GitHub Desktop.
createProcess
#include<stdio.h>
#include<windows.h>
#include<tchar.h>
#define DIR_LEN BUFSIZ
//BUFSIZ는 운영체제마다 다른 크기를 가지고 있습니다.
//한번 크기를 출력해보시는것도 좋겠네요.
int _tmain(int argc, TCHAR* argv[]){
STARTUPINFO si = {0,}; //구조체 선언, 초기화
PROCESS_INFORMATION pi;
si.cb = sizeof(si);
si.lpTitle = _T(" Child process! ");
TCHAR command[] = _T("notepad 10 10");
//10 10은 argv[]로 들어가겠죠, 아래 결과를 보시면
//notepad의 이름으로 들어간다는걸 확인하실 수 있습니다.
BOOL state;
state = CreateProcess(
NULL, //여기에 이름을 넣을 수 있습니다.
command, // 경로를 System에 해줬기 때문에 notepad가 열릴 수 있죠!
NULL,NULL,
TRUE, //부모프로세스중 상속가능한 핸들 상속
CREATE_NEW_CONSOLE, //dwCreationFlags
NULL,NULL,
&si, //STARTUPINFO 구조체 정보를 위에서 만들어줬죠.
&pi //이젠 프로세스의 정보를 가져올때 이 구조체를 사용!
);
if(state!=0){
_fputts(_T("Creation OK! \n"), stdout);
}
else{
_fputts(_T("Creation Fail! \n"), stdout);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment