Summary Files Commits Branches @commit @diff @stats
path: root / Year 3 / System programming / Practice04 / ex2.c
diff options
context:
space:
mode:
Commit952bee4ac4e4a97d30fc1d681ff0a9e5168fb9c8 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-12-02 20:19:43 +0200
Committer
 Syndamia <kamen@syndamia.com>
2023-12-02 20:19:43 +0200
Files673b8d043ed10194694131eeb2948fe4ff94bfac /Year 3/System programming/Practice04/ex2.c
uni-projects-952bee4ac4e4a97d30fc1d681ff0a9e5168fb9c8.tar
uni-projects-952bee4ac4e4a97d30fc1d681ff0a9e5168fb9c8.tar.gz
uni-projects-952bee4ac4e4a97d30fc1d681ff0a9e5168fb9c8.zip
Parentb50c86bd91351bfde316a4aa6e06e95588e4553f (diff)
[SP/P04] Solved exercises
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);
+ }
+}