Stefan Schuermans commited on 2021-03-09 19:21:47
Showing 5 changed files, with 67 additions and 0 deletions.
... | ... |
@@ -0,0 +1,26 @@ |
1 |
+#include <stdlib.h> |
|
2 |
+#include <sys/types.h> |
|
3 |
+#include <sys/wait.h> |
|
4 |
+#include <unistd.h> |
|
5 |
+ |
|
6 |
+void run(char const *path) { |
|
7 |
+ pid_t child = fork(); |
|
8 |
+ if (child == 0) { |
|
9 |
+ execl(path, path, NULL); |
|
10 |
+ exit(EXIT_FAILURE); |
|
11 |
+ } else if (child > 0) { |
|
12 |
+ waitpid(child, NULL, 0); |
|
13 |
+ } |
|
14 |
+} |
|
15 |
+ |
|
16 |
+int main() { |
|
17 |
+ run("/bin/ls"); |
|
18 |
+ pid_t child = fork(); |
|
19 |
+ if (child == 0) { |
|
20 |
+ run("/bin/uptime"); |
|
21 |
+ } else if (child > 0) { |
|
22 |
+ waitpid(child, NULL, 0); |
|
23 |
+ run("/bin/hostname"); |
|
24 |
+ } |
|
25 |
+ return EXIT_SUCCESS; |
|
26 |
+} |
... | ... |
@@ -0,0 +1,24 @@ |
1 |
+#! /bin/bash |
|
2 |
+ |
|
3 |
+set -eux -o pipefail |
|
4 |
+ |
|
5 |
+if (( $# < 1 )) |
|
6 |
+then |
|
7 |
+ echo "usage: $0 <UPT_HOME>" >&2 |
|
8 |
+ exit 2 |
|
9 |
+fi |
|
10 |
+UPT_HOME="$1" |
|
11 |
+ |
|
12 |
+SCRIPT_DIR="$(dirname "$0")" |
|
13 |
+ |
|
14 |
+source "$UPT_HOME/exports" |
|
15 |
+ |
|
16 |
+rm -rf forkapp.upt |
|
17 |
+ |
|
18 |
+upt-trace forkapp.upt "$UPT_HOME/tests/fork/forkapp" |
|
19 |
+ |
|
20 |
+upt-tool forkapp.upt pstree | tee forkapp.pstree |
|
21 |
+ |
|
22 |
+sed -e "s%__UPT_HOME__%$UPT_HOME%" "$SCRIPT_DIR/forkapp.pstree_ref" \ |
|
23 |
+ >forkapp.pstree_ref |
|
24 |
+diff -u forkapp.pstree forkapp.pstree_ref |
|
0 | 25 |