Summary Files Commits Branches @commit @diff @stats
path: root / Year 3 / System programming / Practicum4 / ex2.c
diff options
context:
space:
mode:
1 files changed, 18 insertions, 0 deletions
-rw-r--r--Year 3/System programming/Practicum4/ex2.c18
diff --git a/Year 3/System programming/Practicum4/ex2.c b/Year 3/System programming/Practicum4/ex2.c
new file mode 100644
index 0000000..579b247
--- /dev/null
+++ b/Year 3/System programming/Practicum4/ex2.c
@@ -0,0 +1,18 @@
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <stdio.h>
+
+int main() {
+ pid_t pid = getpid();
+ pid_t fpid = fork();
+ printf("own: %d\nfork: %d\n", pid, fpid);
+ if (fpid == 0) {
+ printf("parent: %d\n", getppid());
+ }
+ else if (fpid > 0) {
+ int childStatus;
+ wait(&childStatus);
+ printf("child exit status: %d\n", childStatus);
+ }
+}