The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
while loop inside while loop panknil Shell Programming and Scripting 0 01-07-2008 12:49 PM
For Loop help princssashes UNIX for Dummies Questions & Answers 2 11-09-2006 05:37 AM
Loop help cjeffers Shell Programming and Scripting 4 06-27-2006 03:32 PM
do...while loop cubs0729 Shell Programming and Scripting 1 09-26-2005 01:49 PM
how to get the similar function in while loop or for loop trynew Shell Programming and Scripting 3 06-17-2002 12:09 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-27-2008
nivea_jmd nivea_jmd is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 2
while loop and CPU ..

Hello frnds..

i m using while loops in my code.. bec of that my application uses almost 90% of CPU resources.. its not lettin others applications to run..

actually i have to read some signal from serial port... n till i dont get it high or low..
i have to read that signal continuously... its for this reason i m using while loops.


while(1)
{
status=read_CTS();
if(status==1)
continue;
else if(status==0)
{

---------
some code
--------

break;
}
}


someone suggested me to use sleep in the while loop..
i cant use it bec we are workin on realtime systems...
so we usually avoid using delay n sleep....

can anyone help me on this ???

my application is on C++/fedora
  #2 (permalink)  
Old 08-27-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,893
The standard call is select(). Do a "man 2 select". It's a little difficult to understand at first, and maybe you have only one file descriptor to wait on, so you can do a man on poll(), but it's not portable to older UNIX's. Here, you can do:


Code:
struct pollfd pollfd_list[] = { 0 /*stdin */, ~0 /* all events */, 0 };
poll( pollfd_list, 1 /* 1 file descriptor */, 1000 /* 1 second */ );

This will return at the latest every second (unless your process is pushed out due to other processes -- Linux isn't realtime) and whether or not you have something to do depends on the last field in pollfd_list.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate 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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:52 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0