Sponsored Content
Top Forums UNIX for Advanced & Expert Users how to use exceptfds argument in select system call Post 302213912 by jim mcnamara on Friday 11th of July 2008 10:17:22 AM
Old 07-11-2008
Code:
 #define MASK(f)     (1 << (f))
           #define NTTYS 4

                int tty[NTTYS];
                int ttymask[NTTYS];
                int readmask = 0;
                int readfds;
                int nfound, i;
                struct timeval timeout;

                   /* First open each terminal for reading and put the
                    * file descriptors into array tty[NTTYS].  The code
                    * for opening the terminals is not shown here.
                    */

                for (i=0; i < NTTYS; i++) {
                   ttymask[i] = MASK(tty[i]);
                   readmask |= ttymask[i];
                }

                timeout.tv_sec  = 5;
                timeout.tv_usec = 0;
                readfds = readmask;

                /* select on NTTYS+3 file descriptors if stdin, stdout
                 * and stderr are also open
                 */
                if ((nfound = select (NTTYS+3, &readfds, 0, 0, &timeout)) == -1)
                   perror ("select failed");
                else if (nfound == 0)
                   printf ("select timed out \n");
                else for (i=0; i < NTTYS; i++)
                   if (ttymask[i] & readfds)
                      /* Read from tty[i].  The code for reading
                       * is not shown here.
                       */
                else printf ("tty[%d] is not ready for reading \n",i);

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

how to differentiate system call from library call

Hi, Ho do I differentiate system call from library call? for example if I am using chmod , how do I find out if it is a system call or library call? Thanks Muru (2 Replies)
Discussion started by: muru
2 Replies

2. Programming

error "Invalid argument" returned after call sched_setscheduler

the code is below and the was run on Solaris 9. ----------------------------- struct sched_param param; param.sched_priority = 99; if(sched_setscheduler(0, SCHED_RR, &param) == -1) { perror("setting priority"); exit(1); } ------------------------------- after the... (1 Reply)
Discussion started by: robin.zhu
1 Replies

3. Shell Programming and Scripting

Function call with argument doubt

Hi all, I am having a problem with user defined function call. I am new into the concept of shell script UDFs. My function is: iterate_directory() { cd $1 k=0 for i in * do if then ARR=${i} fi done echo ${ARR } } (4 Replies)
Discussion started by: canishk
4 Replies

4. Programming

Having some trouble with select() call in C

I have this while loop: while (notdone) { //Set the timers waitd.tv_sec = 5; waitd.tv_usec = 0; FD_ZERO(&tempreadfds); FD_ZERO(&tempwritefds); FD_ZERO(&readfds); /* initialize the read fd set */ FD_ZERO(&writefds); /* initialize the write fd set */ ... (1 Reply)
Discussion started by: Legend986
1 Replies

5. Shell Programming and Scripting

Passing argument to system call in awk script

So, I have this script. It reads a CSV file that has a mixture of object names with IP addresses (parsing out that part I have working), and object names which have a DNS name. I want to be able to run a "dig +short" based off of the name given to me in the line of the awk script, and then deal... (6 Replies)
Discussion started by: mikesimone
6 Replies

6. Programming

select() system call takes longer than the timeout specified

Below is my code. Every once in a while the select call takes as long as 150 seconds (discovered by printing time before and after this statement) while the timeout specified into it is only 1 second. Any clue why? I can't believe that select call which has been around for centuries can have a bug,... (15 Replies)
Discussion started by: old_as_a_fossil
15 Replies

7. UNIX for Dummies Questions & Answers

How to select correct partition and kernel argument for grub?

I use command-line mode of GRUB to load kernel, but I can not know how to chose the partition and kernel argument, as followed : please tell me how to do deal with , thanks! (0 Replies)
Discussion started by: cqlouis
0 Replies

8. Homework & Coursework Questions

program to send messages to parent using pipes and select system call

Write a program using select, which will create some number of child processes that continuously send text messages to the parent process using pipes. Each child has its own pipe that it uses to communicate with the parent. The parent uses select () to decide what pipes should be processed to... (1 Reply)
Discussion started by: ripssingh
1 Replies

9. UNIX for Advanced & Expert Users

Issues with select system call

1. We are using client-server model communication using TCP/IP protocol 2. The TCP socket created with O_NON_BLOCK flag 3. When we make attempt to send large data to other process, the send is partially successful. It means we attempt to send 90K data, OS sent only 40K data successfully. ... (3 Replies)
Discussion started by: MasthanDudekula
3 Replies

10. Shell Programming and Scripting

Conditionally replace nth argument of every function call

I have very large perl source code file and I want to replace every occurrence function say foo,The function foo has some arguments and I want to replace 2nd argument,the current argument is hex integer and i want to replace it to equivalent string.Also I want to replace function name foo with... (4 Replies)
Discussion started by: pravint
4 Replies
PSELECT(2)						      BSD System Calls Manual							PSELECT(2)

NAME
pselect -- synchronous I/O multiplexing a la POSIX.1g LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <sys/select.h> int pselect(int nfds, fd_set * restrict readfds, fd_set * restrict writefds, fd_set * restrict exceptfds, const struct timespec * restrict timeout, const sigset_t * restrict newsigmask); DESCRIPTION
The pselect() function was introduced by IEEE Std 1003.1g-2000 (``POSIX.1'') as a slightly stronger version of select(2). The nfds, readfds, writefds, and exceptfds arguments are all identical to the analogous arguments of select(). The timeout argument in pselect() points to a const struct timespec rather than the (modifiable) struct timeval used by select(); as in select(), a null pointer may be passed to indicate that pselect() should wait indefinitely. Finally, newsigmask specifies a signal mask which is set while waiting for input. When pselect() returns, the original signal mask is restored. See select(2) for a more detailed discussion of the semantics of this interface, and for macros used to manipulate the fd_set data type. RETURN VALUES
The pselect() function returns the same values and under the same conditions as select(). ERRORS
The pselect() function may fail for any of the reasons documented for select(2) and (if a signal mask is provided) sigprocmask(2). SEE ALSO
kqueue(2), poll(2), select(2), sigprocmask(2) STANDARDS
The pselect() function conforms to IEEE Std 1003.1-2001 (``POSIX.1''). HISTORY
The pselect() function first appeared in FreeBSD 5.0. AUTHORS
The first implementation of pselect() function and this manual page were written by Garrett Wollman <wollman@FreeBSD.org>. BSD
October 27, 2009 BSD
All times are GMT -4. The time now is 11:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy