Linux - Newbie This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
05-17-2010, 09:00 PM
|
#1
|
|
LQ Newbie
Registered: May 2010
Posts: 6
Rep:
|
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
|
|
|
|
05-17-2010, 09:02 PM
|
#2
|
|
Member
Registered: Apr 2010
Posts: 82
Rep:
|
Welcome to LQ!
Can you please give us some more detail on the actually process and its function?
|
|
|
|
05-17-2010, 09:27 PM
|
#3
|
|
LQ Newbie
Registered: May 2010
Posts: 6
Original Poster
Rep:
|
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.
|
|
|
|
05-17-2010, 09:52 PM
|
#4
|
|
Member
Registered: Apr 2010
Posts: 82
Rep:
|
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...
|
|
|
|
05-18-2010, 12:34 AM
|
#5
|
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian Squeeze (server), Slackware 13.37 (netbook), Slackware64 14.0 (desktop),
Posts: 8,357
|
Duplicate thread. Original (with no posts except from the OP) is at http://www.linuxquestions.org/questi...t-zero-808472/
|
|
|
|
05-18-2010, 01:20 AM
|
#6
|
|
LQ Newbie
Registered: May 2010
Posts: 6
Original Poster
Rep:
|
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?
|
|
|
|
05-18-2010, 03:10 AM
|
#7
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 15,021
|
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...
|
|
|
|
05-18-2010, 07:16 AM
|
#8
|
|
ELF Statifier author
Registered: Oct 2007
Posts: 648
Rep: 
|
Quote:
Originally Posted by sanil.rc
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() }.
|
|
|
|
05-28-2010, 11:43 PM
|
#9
|
|
LQ Newbie
Registered: May 2010
Posts: 6
Original Poster
Rep:
|
Hi all, nano sleep in fgets loop worked. thank you all.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:03 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|