Find the answer to your Linux question:
Results 1 to 2 of 2
Hello I am having a problem while running my app in a shared environment because it is very cpu intensive. Is there anyway I can get the app to take ...
  1. #1
    Just Joined!
    Join Date
    Jan 2008
    Posts
    22

    CPU utilization time

    Hello
    I am having a problem while running my app in a shared environment because it is very cpu intensive. Is there anyway I can get the app to take it easy on the cpu (my coding in sleeps ets).

    Here is what is happenning

    I have about 16 socket connections , on which I issue a select statement and keep processing the messages from these sockets as and when they are received. The only problem is that I am being flooded with important messages which I handle very well but this sucks the cpu dry, and others on the machine start complaining.
    I then resorted to something like this
    Code:
    //Induce a sleep every 4000 msgs to minimize CPU usage
    if((mmap_counter%4000 == 0) && !do_not_sleep)
    {
         oeslog(log_fp, LOG_STAT, "Sleeping for 4 secs;mmap_counter=%d",mmap_counter);
         sleep(4);
    }
    Is there an alternate way to do this. I was told by someone that its not good to code in sleeps.

    thanks

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Code:
    man 2 nice
    man 2 setpriority
    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...