LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   My process in background hogs 96% CPU but when ran in foreground its almost zero (https://www.linuxquestions.org/questions/linux-newbie-8/my-process-in-background-hogs-96-cpu-but-when-ran-in-foreground-its-almost-zero-808476/)

sanil.rc 05-17-2010 09:00 PM

My process in background hogs 96% CPU but when ran in foreground its almost zero
 
Hi, I am new to this Forum.

I am trying to solve one problem: When i run my process in background it hogs around 96% of CPU.
But when ran in foreground, CPU utilization is almost zero.
Is there any difference b/n a background and a foreground process wrto CPU utilization?

Any help in this regard will be appreciated.

Thanks

kurwongbah 05-17-2010 09:02 PM

Welcome to LQ!

Can you please give us some more detail on the actually process and its function?

sanil.rc 05-17-2010 09:27 PM

The process has 4 threads, 2 of them are TCP server threads waiting for two different client to connect. 3rd one is waiting on shell for user input, it is in while(1){ fgets() }. 4th thread is waiting on a queue to receive some messages.

kurwongbah 05-17-2010 09:52 PM

Hi sanil.rc,
I'm confused here. You say you have a thread that waits for user input and you want to run that in the background?!
You might not want to do that ;)
Or does it wait on some other channel on user input?

Is it software of your own making?
If so, try and disable the user input thread and try to run again.

Could be anything, just trying...

catkin 05-18-2010 12:34 AM

Duplicate thread. Original (with no posts except from the OP) is at http://www.linuxquestions.org/questi...t-zero-808472/

sanil.rc 05-18-2010 01:20 AM

Hi kurwongbah,

U got the point, there is a thread which is waiting for user input from stdin via fgets. Normally this process is not meant to run in background. For some specific reasons i am running it in background. So the question exactly is whether running a process with fgets waiting on stdin will cause such a behaviour?

chrism01 05-18-2010 03:10 AM

This is a bit of a guess, but if you background it you effectively disconnect stdin, which is normally waiting on a terminal cxn. I think its then not waiting on fgets() but infinitely looping, very fast...

Valery Reznic 05-18-2010 07:16 AM

Quote:

Originally Posted by sanil.rc (Post 3972209)
The process has 4 threads, 2 of them are TCP server threads waiting for two different client to connect. 3rd one is waiting on shell for user input, it is in while(1){ fgets() }. 4th thread is waiting on a queue to receive some messages.

Try to add some small sleep, say usleep(1000) in the loop
Code:

while(1){ fgets() }.

sanil.rc 05-28-2010 11:43 PM

Hi all, nano sleep in fgets loop worked. thank you all.


All times are GMT -5. The time now is 06:24 PM.