High kernel usage using sleep

Hi

I have a lot of scripts running on a Sun Solaris server, which are constantly running in a loop looking for work to do. When they have no work they sleep for a certain amount of time (60secs normally). I have 13 of these scripts running the number of sleep command issued can be in the order of 40,000 per hour.

This level of sleeping is causing higher than normal kernel usage.

Is there an alternative to sleep which will not cause so much kernel usage? Or can anyone suggest anything else.

Thanks,

Sleeping processes do not cause kernel usage.

I have noticed that when the shell scripts are down then the kernel usuage returns back to normal.

Can you suggest anything in a script that would then? The scripts are doing usual things like sqlplus calls, writing/reading from files, ls, ps commands - nothing out of the ordinary. These scripts are running 24/7.

Kernel usage on behalf of a process means that the kernel is running a system call. The pause() system is only charged for kernel time while it is putting the process to sleep and once the signal arrives, it gets charged again until it returns. That is only a few microseconds. The 60 seconds that the process spends sleeping does not count as kernel time. If the processes are really being charged for kernel time, they must be invoking other system calls. sleep will be a separate process. So will ps, etc. The shell itself can't be using much kernel time.

sqlplus and sleeping 60 seconds (typically) is not out of the ordinary? How are you calling sqlplus? Most scripts that I see use something like this:

sqlplus us/pw <<EOF
   ...
EOF

Spawning sqlplus every 60 seconds with a login request takes time. You could try a sqlplus co-process and establish one connection for the life of your script.

sqlplus -s /nolog |&
print -p "connect un/pw"

Then you can use print -p and read -p to communicate to the resident sqlplus session.