LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-14-2007, 05:07 AM   #1
expeliarmus
LQ Newbie
 
Registered: Jul 2007
Posts: 17

Rep: Reputation: 0
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
     }
   }
}
 
Old 08-14-2007, 05:11 AM   #2
expeliarmus
LQ Newbie
 
Registered: Jul 2007
Posts: 17

Original Poster
Rep: Reputation: 0
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..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how can you pause child/parent processes in C and execute another function. expeliarmus Programming 5 08-06-2007 01:04 AM
How to rebuild the parent-child relationship of processes? whererush Programming 2 05-19-2006 02:17 PM
sleep() looking for a way to pause execution for fractions of a second qwijibow Programming 3 02-20-2005 02:38 AM
Parent child processes signal sharing iftiuk Programming 8 06-24-2004 01:32 PM
parent and child processes skora Programming 5 11-02-2003 10:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration