My process in background hogs 96% CPU but when ran in foreground its almost zero
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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?
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.
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.
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?
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...
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.