Hi.
this is the algorithm am trying to implement to control Load average.I am having problems waking up selected sleeping child processes.Am using signals. As soon as the load is greater than the desired load,the parent sends a SIGUSR1 to a child process which in turn invokes a function that causes the child to sleep.after this,the program terminates.
How do i make the parent process resume control and wakeup sleeping processes or make more child processes go to sleep depending on whether the load is lesser or greater than a desired load?.
thanks.
Code:
main()
{
get number to do job;
get desired load;
for(;;)
{
do fork()
in parent
{
getload avg;
if loadavg>desiredload
{
// kill children
// exit
set flag;
}
if(flag is set)
{
check load;
while (load>desired load)
make child processes sleep
while(load<desired load)
wake up sleeping child processes
} }
in children
{
if sleep signal is recevied,sleep(),till wakeup call is received;
else do job
}
}
}