-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
35 lines (30 loc) · 778 Bytes
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <pfork.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/wait.h>
int main(int argc, char *argv[]) {
char *args[argc];
// Copy command line arguments to args array
for (int i = 1; i < argc; i++) {
args[i - 1] = argv[i];
}
args[argc - 1] = NULL; // Null-terminate the array
skeleton_daemon();
// Create a child process
pid_t pid = fork();
switch (pid) {
case -1:
// Error occurred
perror("fork");
return 1;
case 0:
// This is the child process
// Execute the command directly
execvp(args[0], args);
// execvp only returns if an error occurs
perror("execvp");
exit(1);
}
}