Blame test/pid.awk

Packit 575503
# From: John C. Oppenheimer <jco@slinky.convex.com>
Packit 575503
# Subject: gawk-3.0.2 pid test
Packit 575503
# To: arnold@skeeve.atl.ga.us
Packit 575503
# Date: Mon, 10 Feb 1997 08:31:55 -0600 (CST)
Packit 575503
# 
Packit 575503
# Thanks for the very quick reply.
Packit 575503
# 
Packit 575503
# This all started when I was looking for how to do the equivalent of
Packit 575503
# "nextfile." I was after documentation and found our gawk down a few
Packit 575503
# revs.
Packit 575503
# 
Packit 575503
# Looks like the nextfile functionality was added somewhere around
Packit 575503
# 2.15.5.  There wasn't a way to do it, until now! Thanks for the
Packit 575503
# functionality!
Packit 575503
# 
Packit 575503
# Saw the /dev/xxx capability and just tried it.
Packit 575503
# 
Packit 575503
# Anyway, I wrote a pid test.  I hope that it is portable.  Wanted to
Packit 575503
# make a user test, but looks like id(1) is not very portable.  But a
Packit 575503
# little test is better than none.
Packit 575503
# 
Packit 575503
# John
Packit 575503
# 
Packit 575503
# pid.ok is a zero length file
Packit 575503
# 
Packit 575503
# ================== pid.awk ============
Packit 575503
BEGIN {
Packit 575503
#	getline pid <"/dev/pid"
Packit 575503
#	getline ppid <"/dev/ppid"
Packit 575503
# 12/2001: switch to PROCINFO. ADR
Packit 575503
	pid = PROCINFO["pid"]
Packit 575503
	ppid = PROCINFO["ppid"]
Packit 575503
Packit 575503
	if (pid != ok_pid)
Packit 575503
		printf "Bad pid %d, wanted %d\n", pid, ok_pid
Packit 575503
	else
Packit 575503
		print "PID ok"
Packit 575503
Packit 575503
	if (ppid != ok_ppid)
Packit 575503
		printf "Bad ppid %d, wanted %d\n", ppid, ok_ppid
Packit 575503
	else
Packit 575503
		print "PPID ok"
Packit 575503
Packit 575503
	# ADR --- added
Packit 575503
#	close("/dev/pid")
Packit 575503
#	close("/dev/ppid")
Packit 575503
Packit 575503
	print "All Done."
Packit 575503
}