Skip to content

Instantly share code, notes, and snippets.

@jshardy
Created February 26, 2019 09:13
Show Gist options
  • Save jshardy/4b1bffbeafa917a75b13481849959a31 to your computer and use it in GitHub Desktop.
Save jshardy/4b1bffbeafa917a75b13481849959a31 to your computer and use it in GitHub Desktop.
Fork Exec
// 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