Last active
December 24, 2015 22:38
-
-
Save figengungor/6873724 to your computer and use it in GitHub Desktop.
Child Process in Windows Lab1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<Windows.h> | |
int main(int argc, char* argv[]) | |
{ | |
//we'll execute this child process with one argument from parent process, | |
//so we are checking if the number of arguments is right. | |
//If you wanna give more arguments, check according to this. | |
//argc is the number of arguments + 1(process that is executed) | |
// ex: child.exe 1 => argc=2 , calculator.exe "what's up?" "hey" "yov" 4 => argc=5 | |
if(argc!=2) | |
{ | |
printf("error in child process"); | |
system("pause"); | |
exit(0); | |
} | |
//if everything goes right, then let's print the argument given to this child. | |
//argv[0] is the name of process(child.exe in this case), argv[1] is first arg, argv[2] is second | |
//and it goes on as you wish. | |
printf("message from parent: %s \n", argv[1]); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment