Created
February 26, 2019 09:13
-
-
Save jshardy/4b1bffbeafa917a75b13481849959a31 to your computer and use it in GitHub Desktop.
Fork Exec
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
// Returns proccess return value | |
int CreateProcess(char **cmdArgs) | |
{ | |
pid_t pid = 0; | |
int rval = 0; | |
pid = fork(); | |
// if pid == 0 then I'm in child | |
if(pid == 0) | |
{ | |
execvp(*cmdArgs, cmdArgs); | |
// if we make it here then there was an error execing | |
printf(COLOR_RED "%s: Bad command or filename." COLOR_RESET, *cmdArgs); | |
exit(EXIT_FAILURE); | |
} | |
// In parent | |
wait(&rval); | |
return rval; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment