#! /usr/bin/perl

# "start daemon" -- Start the tpaged daemon if it isn't running.
#   by Tom Limoncelli, tal@warren.mentorg.com
#   Copyright (c) 1992, Tom Limoncelli


$BSD = -f '/vmunix';
#$pscmd = $BSD ? "ps -auxww" : "ps -ef";
$pscmd = "ps -auxww";

open(PS, "$pscmd|") || die "Can't run ps: !$";
$title = <PS>;
$found = 0;
while (<PS>) {
	chop;
	$found = 1 if /tpaged/;
}

if (!$found) {
	unless (fork) {	#	this is the child
		unless (fork) {	#	this is the child's child
			sleep 1 until getppid == 1;
			system "/usr/local/etc/tpage/tpaged &";
			exit 0;
		}
		exit 0;
	}
	print "Started tpaged\n";
}
