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