1# From: John C. Oppenheimer <jco@slinky.convex.com>
2# Subject: gawk-3.0.2 pid test
3# To: arnold@skeeve.atl.ga.us
4# Date: Mon, 10 Feb 1997 08:31:55 -0600 (CST)
5#
6# Thanks for the very quick reply.
7#
8# This all started when I was looking for how to do the equivalent of
9# "nextfile." I was after documentation and found our gawk down a few
10# revs.
11#
12# Looks like the nextfile functionality was added somewhere around
13# 2.15.5.  There wasn't a way to do it, until now! Thanks for the
14# functionality!
15#
16# Saw the /dev/xxx capability and just tried it.
17#
18# Anyway, I wrote a pid test.  I hope that it is portable.  Wanted to
19# make a user test, but looks like id(1) is not very portable.  But a
20# little test is better than none.
21#
22# John
23#
24# pid.ok is a zero length file
25#
26# ================== pid.awk ============
27BEGIN {
28#	getline pid <"/dev/pid"
29#	getline ppid <"/dev/ppid"
30# 12/2001: switch to PROCINFO. ADR
31	pid = PROCINFO["pid"]
32	ppid = PROCINFO["ppid"]
33
34	if (pid != ok_pid)
35		printf "Bad pid %d, wanted %d\n", pid, ok_pid
36	else
37		print "PID ok"
38
39	if (ppid != ok_ppid)
40		printf "Bad ppid %d, wanted %d\n", ppid, ok_ppid
41	else
42		print "PPID ok"
43
44	# ADR --- added
45#	close("/dev/pid")
46#	close("/dev/ppid")
47
48	print "All Done."
49}
50