aboutsummaryrefslogtreecommitdiffstats
path: root/test/fork.awk
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2012-05-09 20:31:35 +0300
committerArnold D. Robbins <arnold@skeeve.com>2012-05-09 20:31:35 +0300
commita59319732d89feda419acab674ea580c95db7d4a (patch)
tree3d30595e8f50cb1b486c9f61f93a498834c22842 /test/fork.awk
parent8ff0b4eaa7592280b5a55087c0326c6ef1f88db5 (diff)
parentc41908d0b02f7746a67ab7aa2e54058e5b66439a (diff)
downloadegawk-a59319732d89feda419acab674ea580c95db7d4a.tar.gz
egawk-a59319732d89feda419acab674ea580c95db7d4a.tar.bz2
egawk-a59319732d89feda419acab674ea580c95db7d4a.zip
Merge branch 'xgawk'
Diffstat (limited to 'test/fork.awk')
-rw-r--r--test/fork.awk33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/fork.awk b/test/fork.awk
new file mode 100644
index 00000000..0b29f9ff
--- /dev/null
+++ b/test/fork.awk
@@ -0,0 +1,33 @@
+@load "fork"
+
+BEGIN {
+ fn = ("fork.tmp." PROCINFO["pid"])
+ switch (pid = fork()) {
+ case -1:
+ printf "Error: fork failed with ERRNO %s\n", ERRNO
+ exit 1
+ case 0:
+ # child
+ printf "pid %s ppid %s\n", PROCINFO["pid"], PROCINFO["ppid"] > fn
+ exit 0
+ default:
+ # parent
+ erc = 1
+ if ((rc = wait()) < 0)
+ printf "Error: wait failed with ERRNO %s\n", ERRNO
+ else if (rc != pid)
+ printf "Error: wait returned %s instead of child pid %s\n", rc, pid
+ else if ((getline x < fn) != 1)
+ printf "Error: getline failed on temp file %s\n", fn
+ else {
+ expected = ("pid " pid " ppid " PROCINFO["pid"])
+ if (x != expected)
+ printf "Error: child data (%s) != expected (%s)\n", x, expected
+ else if ((rc = system("rm " fn)) != 0)
+ printf "Error removing temp file %s with ERRNO %s\n", fn, ERRNO
+ else
+ erc = 0
+ }
+ exit erc
+ }
+}