Endless loop - Fork function failed?

I need a quick script that will serve as a sort of "real time monitor" for watching some log files. I am using Bourne shell in HP-UX 10.20. I have basically created a script that never ends, unless of course I manually terminate it. Here's the script (it's called qhistory):

clear
echo "REAL TIME MONITOR - QCHECK"
echo "=========================="
echo
qcheck
sleep 1
qhistory

As you can see, if executes the qcheck command, sleeps for a second, then does the same thing over and over.

The script is doing exactly what I want it to do for about 5 minutes, then it dies. I get the following error:

qhistory[3]: The fork function failed. Too many processes already exist.

I'm a rookie at this, and don't reall know the best way to create this "real time monitor". Any suggestions? Thanks!!

-cd

Instead of looping, you are starting another child process which runs another instance of qhistory. The error is telling you that you can't do this anymore.

I can't tell from your code what scripting language you are using so here is a csh example:

#!/bin/csh -f
loop:
echo "Hostname: `hostname`"
mailq|head
sleep 5
goto loop

That worked. THanks.

Or if you want to stick with /usr/bin/sh, this should work:

#!/usr/bin/sh

while true
do
clear
echo "\n REAL TIME MONITOR - QCHECK"
echo "=======================\n"
qcheck
sleep 3
done

The trick is "while true"... It basically says that any time the "true" command returns true (always), do the following. Another common way of looking like that is to say "while :" - the ":" command will always return true also.