LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   making the parent direct child processes to pause/sleep and resume execution (https://www.linuxquestions.org/questions/programming-9/making-the-parent-direct-child-processes-to-pause-sleep-and-resume-execution-576953/)

expeliarmus 08-14-2007 05:07 AM

making the parent direct child processes to pause/sleep and resume execution
 
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
    }
  }
}


expeliarmus 08-14-2007 05:11 AM

here, "job",is just some junk activity to generate load.In my case,i accept a number(the first line of the algorithm) and compute either the number^number^number..(for example:if number is 3,i calculate 3^3^3^3,if its 2,i calculate 2^2^2)..or the factorial of the number..


All times are GMT -5. The time now is 01:51 PM.