while loop and CPU ..


 
Thread Tools Search this Thread
Top Forums Programming while loop and CPU ..
# 1  
Old 08-27-2008
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  
Old 08-27-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Why Entitlement CPU can't be set to same as Virtual CPU?

I read that Entitlement CPU should be set to max 75% compare to Virtual CPU. May I know the reason. I have set the Entitlement CPU = Virtual CPU on AIX . It works fine . Can you help to understand. (1 Reply)
Discussion started by: gabhanes
1 Replies

2. AIX

Entitled CPU lesser Than Used CPU !!

Hi All, It may be a n00b question, but i really want to know , How Entitled Capacity is less and Used CPU is more when there is no Free CPU is available in the managed system. I have 5LPARs in a MS with Dual VIO. Managed System CPU details Available: 0.20 Assigned to partitions: 15.80... (11 Replies)
Discussion started by: Thala
11 Replies

3. UNIX for Dummies Questions & Answers

Is it possible to combine multiple CPU to act as a single CPU on the same server?

We have a single threaded application which is restricted by CPU usage even though there are multiple CPUs on the server, hence leading to significant performance issues. Is it possible to merge / combine multiple CPUs at OS level so it appear as a single CPU for the application? (6 Replies)
Discussion started by: Dissa
6 Replies

4. Solaris

Difference between CPU CHIP and CPU ID

Hi All, What is the difference between CPU CHIP and CUP ID on SUN/ Oracle M5000 servers.. Thanks in advance (3 Replies)
Discussion started by: kumarmani
3 Replies

5. Solaris

CPU and CPU-Utilization

Hi, I am a weblogic Admin I our env there are 5 servers running in one Solaris 10 Sparc machine. But when i tried for process status using <top> command I got the following output load averages: 1.75, 2.18, 2.12; up 134+08:28:49 22:24:21 79 processes: 77 sleeping, 1 running,... (1 Reply)
Discussion started by: Joseph Antoine
1 Replies

6. Solaris

cpu-shares vs cpu-cap in solaris

Can anyone tell me difference between cpu-shares vs cpu-cap in solaris & how FSS will work with cpu-caps ? (9 Replies)
Discussion started by: fugitive
9 Replies

7. Solaris

Infinite for loop is taking too much CPU usage %

Hi All, I wrote one simple for loop shell script which prints number..but this loop is infinite...but its taking lot of CPU (15.7) %. if i am using sleep cmd then cpu usage become 0.4 %. Is there anyway to reduce this CPU usage without using sleep cmd? i dont want 2 use sleep cmd... (7 Replies)
Discussion started by: pa.chidhambaram
7 Replies

8. Solaris

Multi CPU Solaris system shows 100% CPU usage.

Hello Friends, On one of my Solaris 10 box, CPU usage shows 100% using "sar", "vmstat". However, it has 4 CPUs and prstat and glance are not showing enough processes to justify high CPU utilization. ========================================================================= $ prstat -a ... (4 Replies)
Discussion started by: mahive
4 Replies

9. UNIX for Dummies Questions & Answers

how to get persistant cpu utilization values per process per cpu in linux (! top,ps)

hi, i want to know cpu utilizatiion per process per cpu..for single processor also if multicore in linux ..to use these values in shell script to kill processes exceeding cpu utilization.ps (pcpu) command does not give exact values..top does not give persistant values..psstat,vmstat..does njot... (3 Replies)
Discussion started by: pankajd
3 Replies

10. Solaris

How to down a particular CPU in a server, witch is having 16 CPU's

Hi.., my dout is a solaris server is having 16 cpu's. in tht one cpu running some error process, accupaying more space. I wanna down tht particular CPU only with out interrupting the other 15 CPU's. how can i do this. is there any command for this ?? (5 Replies)
Discussion started by: b.janardhanguru
5 Replies
Login or Register to Ask a Question