Sponsored Content
Full Discussion: while loop and CPU ..
Top Forums Programming while loop and CPU .. Post 302229610 by otheus on Wednesday 27th of August 2008 09:57:14 AM
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.
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
PCAP_GET_SELECTABLE_FD(3)				     Library Functions Manual					 PCAP_GET_SELECTABLE_FD(3)

NAME
pcap_get_selectable_fd - get a file descriptor on which a select() can be done for a live capture SYNOPSIS
#include <pcap/pcap.h> int pcap_get_selectable_fd(pcap_t *p); DESCRIPTION
pcap_get_selectable_fd() returns, on UNIX, a file descriptor number for a file descriptor on which one can do a select() or poll() to wait for it to be possible to read packets without blocking, if such a descriptor exists, or -1, if no such descriptor exists. Some network devices opened with pcap_create() and pcap_activate(), or with pcap_open_live(), do not support select() or poll() (for example, regular network devices on FreeBSD 4.3 and 4.4, and Endace DAG devices), so -1 is returned for those devices. Note that in: FreeBSD prior to FreeBSD 4.6; NetBSD prior to NetBSD 3.0; OpenBSD prior to OpenBSD 2.4; Mac OS X prior to Mac OS X 10.7; select() and poll() do not work correctly on BPF devices; pcap_get_selectable_fd() will return a file descriptor on most of those versions (the exceptions being FreeBSD 4.3 and 4.4), but a simple select() or poll() will not indicate that the descriptor is readable until a full buffer's worth of packets is received, even if the read timeout expires before then. To work around this, an application that uses select() or poll() to wait for packets to arrive must put the pcap_t in non-blocking mode, and must arrange that the select() or poll() have a timeout less than or equal to the read timeout, and must try to read packets after that timeout expires, regardless of whether select() or poll() indicated that the file descriptor for the pcap_t is ready to be read or not. (That workaround will not work in FreeBSD 4.3 and later; however, in FreeBSD 4.6 and later, select() and poll() work correctly on BPF devices, so the workaround isn't necessary, although it does no harm.) Note also that poll() doesn't work on character special files, including BPF devices, in Mac OS X 10.4 and 10.5, so, while select() can be used on the descriptor returned by pcap_get_selectable_fd(), poll() cannot be used on it those versions of Mac OS X. Kqueues also don't work on that descriptor. poll(), but not kqueues, work on that descriptor in Mac OS X releases prior to 10.4; poll() and kqueues work on that descriptor in Mac OS X 10.6 and later. pcap_get_selectable_fd() is not available on Windows. RETURN VALUE
A selectable file descriptor is returned if one exists; otherwise, -1 is returned. SEE ALSO
pcap(3), select(2), poll(2) 22 July 2011 PCAP_GET_SELECTABLE_FD(3)
All times are GMT -4. The time now is 10:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy