Having some trouble with select() call in C


 
Thread Tools Search this Thread
Top Forums Programming Having some trouble with select() call in C
# 1  
Old 02-02-2010
Having some trouble with select() call in C

I have this while loop:

Code:
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 */

		FD_SET(parentfd, &readfds); /* add listener socket fd */
		FD_SET(0, &readfds);        /* add stdin fd (0) */


		tempreadfds = readfds; //make a copy
		tempwritefds = writefds; //make a copy

		rv = select(fdmax+1, &tempreadfds, &tempwritefds, (fd_set*) 0, &waitd);
		if (rv < 0) {
			error("ERROR in select");
		} else if(rv == 0) {
			printf("Timeout occurred! No data after 5 seconds\n");
		}
  
                printf("Select called\n");
		fflush(stdout);
}

I was assuming that "Select called" should be printed every 5 seconds but it gets printed only once. Can someone tell me what mistake I am doing?
# 2  
Old 02-03-2010
Hello,

Quote:
Originally Posted by Legend986
I have this while loop:
<snip>
I was assuming that "Select called" should be printed every 5 seconds but it gets printed only once. Can someone tell me what mistake I am doing?
Difficult to tell from the code you posted. A few questions:
- What do you mean by "it gets printed only once". Do you mean that subsequent select() blocks?
- what's the point with tempreadfs and tempwritefs? Why don't you use readfs/writefs directly?
- where is fdmax set?

Could you perhaps post a minimalistic example that we can compile and that illustrates your problem?

Thanks,
Loïc.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

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

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

3. Boot Loaders

Reboot and Select Proper Boot device or insert Boot media in select Boot device and press a key

Hello, I have kubuntu on my laptop and now I decided to switch to Windows 7. I made the bios settings properly (first choice is boot from cd\vd) but I see the error " reboot and select proper Boot device or insert Boot media in select Boot device and press a key " I have tried CD and... (0 Replies)
Discussion started by: rpf
0 Replies

4. Programming

Trouble with C

Hey, i am having a problem First, i know java well and i have used C++ on occasion so i thought i would be able to deal with a class where they program in C. unfortunately i have hit some speed bumps that i am having problems. Here is my problem: I have a structure cache_t in the sample... (0 Replies)
Discussion started by: zephoid
0 Replies

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

6. UNIX for Dummies Questions & Answers

Why do I need to call make if I call gcc ?

Why do I need to call make if I call gcc ? I thought gcc already compiles the sources. thanks (1 Reply)
Discussion started by: aneuryzma
1 Replies

7. Infrastructure Monitoring

diffrence between method call and function call in perl

Hello, I have a problem with package and name space. require "/Mehran/DSGateEngineLib/general.pl"; use strict; sub System_Status_Main_Service_Status_Intrusion_Prevention { my %idpstatus; my @result; &General_ReadHash("/var/dsg/idp/settings",\%idpstatus); #print... (4 Replies)
Discussion started by: Zaxon
4 Replies

8. UNIX for Advanced & Expert Users

how to use exceptfds argument in select system call

Hi, Can any one tell me how to use the fourth argument of select system call.I saw example "port forwarding" on the net,but it was too complex for me to understand.Can any one explain me about the usage of exceptfds argument of select system call with simple example. Thanks. (2 Replies)
Discussion started by: bvijaya
2 Replies

9. 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
Login or Register to Ask a Question