]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/test/stress2/misc/pdfork.sh
contrib/bc: update to version 5.1.1
[FreeBSD/FreeBSD.git] / tools / test / stress2 / misc / pdfork.sh
1 #!/bin/sh
2
3 # truss / pdfork regression test.
4 # Test scenario by: Ryan Stone rstone@, slightly mangled by pho@
5
6 # Interruptable hang seen:
7 # $ ps -lp992
8 #  UID PID PPID CPU PRI NI  VSZ  RSS MWCHAN STAT TT     TIME COMMAND
9 # 1001 992  991   0  27  0 4168 1908 -      TX+   0  0:00.00 /tmp/pdfork -p
10 # $
11
12 cat > /tmp/pdfork.c <<EOF
13 #include <sys/types.h>
14 #include <sys/procdesc.h>
15 #include <sys/resource.h>
16 #include <sys/time.h>
17 #include <sys/wait.h>
18 #include <err.h>
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include <unistd.h>
23
24 int
25 main(int argc, char **argv)
26 {
27         pid_t pid;
28         int fd;
29
30         if (argc > 1 && strcmp(argv[1], "-p") == 0) {
31                 pid = pdfork(&fd, 0);
32         } else {
33                 pid = fork();
34         }
35
36         if (pid == 0) {
37                 sleep(1);
38                 exit(0);
39         } else if (pid < 0) {
40                 err(1, "fork() failed");
41         } else {
42                 int status = 0;
43                 if (argc > 1 && strcmp(argv[1], "-p") != 0) {
44                         int error = wait4(pid, &status, WEXITED, NULL);
45                         if (error < 0)
46                                 err(1, "wait4 failed");
47                 }
48                 exit(status);
49         }
50 }
51 EOF
52 cc -o /tmp/pdfork -Wall -Wextra -O2 /tmp/pdfork.c || exit 1
53
54 timeout 20s truss -f /tmp/pdfork    2> /dev/null; s1=$?
55 timeout 20s truss -f /tmp/pdfork -p 2> /dev/null; s2=$?
56
57 rm -f /tmp/pdfork /tmp/pdfork.c
58 return $((s1 + s2))