LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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

Reply
 
Search this Thread
Old 05-17-2010, 09:00 PM   #1
sanil.rc
LQ Newbie
 
Registered: May 2010
Posts: 6

Rep: Reputation: 0
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
 
Old 05-17-2010, 09:02 PM   #2
kurwongbah
Member
 
Registered: Apr 2010
Posts: 82

Rep: Reputation: 23
Welcome to LQ!

Can you please give us some more detail on the actually process and its function?
 
Old 05-17-2010, 09:27 PM   #3
sanil.rc
LQ Newbie
 
Registered: May 2010
Posts: 6

Original Poster
Rep: Reputation: 0
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.
 
Old 05-17-2010, 09:52 PM   #4
kurwongbah
Member
 
Registered: Apr 2010
Posts: 82

Rep: Reputation: 23
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...
 
Old 05-18-2010, 12:34 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,551
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Duplicate thread. Original (with no posts except from the OP) is at http://www.linuxquestions.org/questi...t-zero-808472/
 
Old 05-18-2010, 01:20 AM   #6
sanil.rc
LQ Newbie
 
Registered: May 2010
Posts: 6

Original Poster
Rep: Reputation: 0
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?
 
Old 05-18-2010, 03:10 AM   #7
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,283

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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...
 
Old 05-18-2010, 07:16 AM   #8
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 666

Rep: Reputation: 133Reputation: 133
Quote:
Originally Posted by sanil.rc View Post
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() }.
 
Old 05-28-2010, 11:43 PM   #9
sanil.rc
LQ Newbie
 
Registered: May 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Hi all, nano sleep in fgets loop worked. thank you all.
 
  


Reply

Tags
background, cpu, diff, foreground, post, process


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
My process in background hogs 96% CPU but when ran in foreground its almost zero. sanil.rc Linux - Embedded & Single-board computer 2 05-18-2010 12:38 AM
how to move background process to foreground batola Linux - Server 29 03-10-2010 10:28 AM
background process popping up in foreground noir911 Linux - General 1 12-14-2007 11:53 PM
Foreground and Background program switching isolvesystems Linux - Newbie 2 10-03-2007 09:30 AM
Background and Foreground Datamike Linux - Software 2 01-20-2006 04:20 PM


All times are GMT -5. The time now is 10:03 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration