Summary Files Commits Branches @commit @diff @stats
path: root / Year 3 / System programming / Practicum5 / ex5.c
diff options
context:
space:
mode:
1 files changed, 21 insertions, 0 deletions
-rw-r--r--Year 3/System programming/Practicum5/ex5.c21
diff --git a/Year 3/System programming/Practicum5/ex5.c b/Year 3/System programming/Practicum5/ex5.c
new file mode 100644
index 0000000..49fe3e2
--- /dev/null
+++ b/Year 3/System programming/Practicum5/ex5.c
@@ -0,0 +1,21 @@
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include <stdio.h>
+
+int main(int argc, char *argv[]) {
+ pid_t f = fork();
+ if (f < 0) {
+ perror("fork");
+ return 1;
+ }
+
+ if (f == 0) {
+ execvp(argv[1], argv + 1);
+ }
+ else {
+ int status = -2;
+ wait(&status);
+ printf("Child: %d\tExit: %d\n", f, status);
+ }
+}