Sponsored Content
Full Discussion: Multiple fds in select()
Top Forums Programming Multiple fds in select() Post 31760 by amatsaka on Wednesday 13th of November 2002 08:07:07 AM
Old 11-13-2002
Lightbulb Multiple fds in select()

Hi

I want to read messages from multiple interfaces using one select() statement. Does anybody knows if I can specify multiple fds in the *readfds parameter? If yes, what's the max num of fds?
Something like the following:


fd_set descrSet = {0};
int retVal;
MyStructS *msg = NULL;

while{
FD_ZERO(&descrSet);
FD_SET(Intf1SockNum, &descrSet);
FD_SET(Intf2SockNum, &descrSet);
FD_SET(Intf3SockNum, &descrSet);
.
.
FD_SET(IntfnSockNum, &descrSet);

/* wait for msg / timeout */
retVal = select(FD_SETSIZE, &descrSet, NULL, NULL, &timeout);

/*check what happened */
switch (retVal){
case -1:
/* handle error */
break;

case 0:
/* timeout before msg arrived */
break;

default:
if (FD_ISSET(Intf1SockNum, &descrSet)){
retVal = ReadMsgfromIntf1(&msg);
/* handle msg rxed*/
} /* if */
if (FD_ISSET(Intf2SockNum, &descrSet)){
retVal = ReadMsgfromIntf2(&msg);
/* handle msg rxed*/
} /* if */
.
.
if (FD_ISSET(IntfnSockNum, &descrSet)){
retVal = ReadMsgfromIntf3(&msg);
/* handle msg rxed*/
} /* if */
} /* switch*/
} /* while */

Thanx
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Should a UNIX daemon process close open fds?

I have a UNIX daemon process that's been started by a parent process, an application server. The behavior of this daemon process is to inherit and use the app server's file descriptors (ports/sockets). When I shutdown the app server, the daemon continues to run, because there may be other... (1 Reply)
Discussion started by: kunalashar
1 Replies

2. Shell Programming and Scripting

Dynamic select with multiple word menu items

Hello all, I'm developing a deployment script at work and at one point it would need to display something like this: Which version of ADMIN would you like to deploy? 1) 1.0.0 (store1, 10 Jan 2004) 2) 1.0.1 (store1, 20 Jun 2004) 3) 1.0.2 (store1, 15 Jul 2004) Select a version : I know... (5 Replies)
Discussion started by: domivv
5 Replies

3. UNIX for Dummies Questions & Answers

Select Distinct on multiple fields

How do I create a script that provides a count of distinct values of a particular field in a file utilizing commonly available UNIX commands (sh or awk)? Field1|Field2|Field3|Field4 AAA|BBB|CCC|DDD 111|222|333|777 AAA|EEE|ZZZ|EEE 111|555|333|444 AAA|EEE|CCC|DDD 111|222|555|444 For... (2 Replies)
Discussion started by: Refresher
2 Replies

4. Shell Programming and Scripting

Is is possible to pass multiple entries in PS3 select ?

PS3="Enter corresponding number and hit enter:" select DIR in `cat mylist` QUIT do if then echo "INVALID INPUT" else if ; then my commands ..... else break fi fi REPLY='' done The above will return something like below : Select from the list of... (4 Replies)
Discussion started by: ningy
4 Replies

5. Shell Programming and Scripting

Connecting sqlplus from UNIX with multiple select statement

hi, i have a requirement where i need to connect sqlplus from unix and i am able to do so by following command: cust_count=`sqlplus -s $ORACLE_USER/$ORACLE_PASS@$ORACLE_SID << EOF set pagesize 0 set feedback off set verify off ... (1 Reply)
Discussion started by: lovelysethii
1 Replies

6. Shell Programming and Scripting

How to use a multiple line list with the select command in ksh?

I copied the below program to play around with displaying a list of items using the select command in ksh. When I put all items in the same line, it works fine. I am trying to use multiple lines instead of a single row...my list is too large for a single line. How do I get the line continuation... (3 Replies)
Discussion started by: haganator
3 Replies

7. Shell Programming and Scripting

Concatenate select lines from multiple files

I have about 6000 files of the following format (three simplified examples shown; actual files have variable numbers of columns, but the same number of lines). I would like to concatenate the ID (*Loc*) and data lines, but not the others, as shown below. The result would be one large file (or... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

8. Shell Programming and Scripting

Select answers from multiple questions using shell script

I have a text file in this format Some lines.... Question no: 1 The question? A. Answer 1 B. Answer 2 C. Answer 3 D. Answer 4 Answer:B Some lines.... Question no: 2 The question? (choose 2) (10 Replies)
Discussion started by: zorrox
10 Replies

9. Shell Programming and Scripting

Select multiple column from multiple files

Hi Friends, $ cat test1.txt emeka:1438 shelley:1439 dmeyer:1440 kurtarn:1441 abdul:1442 $ cat test2.txt 1:a 2:b 3:c 4:d $ cat test3.txt cat:dog:bat man:hot:cold (5 Replies)
Discussion started by: Jewel
5 Replies

10. Shell Programming and Scripting

Shell Scripting - Select multiple files from numbered list

I am trying to have the user select two files from a numbered list which will eventually be turned into a variable then combined. This is probably something simple and stupid that I am doing. clear echo "Please Select the Show interface status file" select FILE1 in *; echo "Please Select the... (3 Replies)
Discussion started by: dis0wned
3 Replies
GETFDS(3PVM)							  PVM Version 3.4						      GETFDS(3PVM)

NAME
pvm_getfds - Get file descriptors in use by PVM. SYNOPSIS
C int nfds = pvm_getfds( int **fds ) Fortran Not Available PARAMETERS
fds Returns integer array of file descriptors. DESCRIPTION
A PVM task uses sockets to communicate between libpvm and other tasks or the pvmd. It is sometimes useful to know the file descriptor num- bers of the sockets in order to wait from input from either PVM messages or an external source. For example, the PVM console waits on both keyboard input and notify messages. Input can be multiplexed by polling all sources, but this wastes cpu cycles. Instead, the select() system call can be used to wait until one or more sources of input are ready. If it completes successfully, pvm_getfds returns the number of sockets in use, and the file descriptor numbers in an array (allocated and freed by libpvm). At least one socket always exists (from task to pvmd), and its descriptor is always fds[0]. The number of sockets varies as direct routes are established to other tasks. It can be difficult to track the set of file descriptors if direct routing is enabled, because routes are created as messages are either sent or received. The simplest approach is to disable direct routing. When select returns with a PVM file descriptor ready, a complete message may be ready to be received, or instead only a fragment may be waiting. pvm_nrecv or pvm_probe should be used test without blocking. RESTRICTIONS
pvm_getfds is only available when running PVM on a Unix or similar system. EXAMPLES
The following program fragment waits until either keyboard input is available, or a PVM message has arrived. int *d; fd_set r; pvm_setopt(PvmRoute, PvmDontRoute); pvm_getfds(&d); FD_ZERO(&r); FD_SET(0, &r); FD_SET(d[0], &r); while(1) { if (select(d[0] + 1, &r, (fd_set*)0, (fd_set*)0, (struct timeval*)0) > 0) { if (FD_ISSET(0, &r)) ... /* read keyboard input */ if (FD_ISSET(d[0], &r) && pvm_nrecv(-1, -1) > 0) ... /* got a PVM message */ } } ERRORS
The following error condition can be returned by pvm_getfds: PvmSysErr pvmd not responding. SEE ALSO
pvm_notify(3PVM), pvm_trecv(3PVM) 22 Nov, 1994 GETFDS(3PVM)
All times are GMT -4. The time now is 07:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy