Summary Files Commits Branches @commit @diff @stats
path: root / Year 3 / System programming / Practice04 / ex3.c
diff options
context:
space:
mode:
1 files changed, 16 insertions, 0 deletions
-rw-r--r--Year 3/System programming/Practice04/ex3.c16
diff --git a/Year 3/System programming/Practice04/ex3.c b/Year 3/System programming/Practice04/ex3.c
new file mode 100644
index 0000000..dc32819
--- /dev/null
+++ b/Year 3/System programming/Practice04/ex3.c
@@ -0,0 +1,16 @@
+#include <unistd.h> // fork, execl
+#include <sys/wait.h> // wait
+#include <sys/types.h> // pid_t
+#include <stdio.h> // printf
+
+int main(int argc, char* argv[]) {
+ pid_t f = fork();
+ if (f == 0) { // in child
+ execl(argv[1], argv[1], (char*)NULL);
+ }
+ else {
+ int status;
+ wait(&status);
+ printf("Exit status: %d\n", status);
+ }
+}