b28a6bcf29
Signed-off-by: kaguya3311 <kaguya3311@national.shitposting.agency>
34 lines
646 B
C
34 lines
646 B
C
#include <unistd.h>
|
|
#include <sys/wait.h>
|
|
#include <stdio.h>
|
|
|
|
int main() {
|
|
printf("\nforking!");
|
|
pid_t pid = fork();
|
|
|
|
if (pid < 0) {
|
|
perror("fork failed");
|
|
return 1;
|
|
}
|
|
|
|
if (pid == 0) {
|
|
// Child process
|
|
printf("child processed!");
|
|
char *argv[] = {"/bin/pwd", NULL};
|
|
char *envp[] = {NULL};
|
|
|
|
execve("/bin/pwd", argv, envp);
|
|
|
|
// If execve returns, it failed
|
|
perror("execve failed");
|
|
return 1;
|
|
} else {
|
|
// Parent process
|
|
waitpid(pid, NULL, 0);
|
|
printf("Child process finished\n");
|
|
}
|
|
|
|
printf("comp");
|
|
|
|
return 0;
|
|
} |