myshellin/doc/code/launch.txt

21 lines
463 B
Plaintext
Raw Normal View History

2021-07-17 14:15:52 -04:00
void launch_program(StringArray *args) {
pid_t child = 0;
child = fork();
if (child == 0) {
if (execvp(args->array[0], args->array) == -1) {
fprintf(stderr, "%s: command not found\n", args->array[0]);
free_string_array(args);
exit(EXIT_FAILURE);
}
}
else if (child < 0) {
perror("fork");
}
else {
int child_status;
waitpid(child, &child_status, 0);
}
}