Date: Thu, 03 Jan 2008 11:57:25 -0800 From: Garrett Cooper <youshi10@u.washington.edu> To: Metin KAYA <metin@EnderUNIX.org> Cc: freebsd-hackers@freebsd.org, "Rick C. Petty" <rick-freebsd@kiwi-computer.com> Subject: Re: select Message-ID: <477D3E25.4080807@u.washington.edu> In-Reply-To: <477D3977.3030608@u.washington.edu> References: <1571995824.20080103205248@EnderUNIX.org> <20080103192245.GB90170@keira.kiwi-computer.com> <363446479.20080103213223@EnderUNIX.org> <477D3977.3030608@u.washington.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
Garrett Cooper wrote: > Metin KAYA wrote: >> Yes Rick, I'm asking this "indefinitely" issue. Is there anything >> that handle this NULL situation a signal, or etc.? How does Linux or >> FreeBSD behave? >> >> >>> On Thu, Jan 03, 2008 at 08:52:48PM +0200, Metin KAYA wrote: >>> >>>> How select(2) will behave if I give the "utimeout" parameter as >>>> NULL? >>>> >> >> >>> According to the man page: >>> >> >> >>> If timeout is not a null pointer, it specifies the maximum >>> interval to >>> wait for the selection to complete. System activity can >>> lengthen the >>> interval by an indeterminate amount. >>> >> >> >>> If timeout is a null pointer, the select blocks indefinitely. >>> >> >> >>> To effect a poll, the timeout argument should not be a null >>> pointer, but >>> it should point to a zero-valued timeval structure. >>> >> >> >> >>> -- Rick C. Petty >>> >> >> >> -- Metin KAYA EnderUNIX >> Software Developer Endersys Software Engineer >> http://www.EnderUNIX.org/metin http://www.Endersys.com/ >> > Nevermind -- yes, block indefinitely, which implies that the program > won't proceed until it receives an umasked signal and exits or a file > descriptor becomes available in the 'infinite' time frame. > > That would essentially be the same as listen or send though with > blocking sockets, correct? > > -Garrett Give this beauty a shot [manually modified from the FC7 select(2) manpage]: #include <stdio.h> #include <sys/select.h> int main() { fd_set rfds; FD_ZERO(&rfds); FD_SET(0, &rfds); printf("Wait for it...\n"); select(1, &rfds, NULL, NULL, NULL); printf("Done!\n"); return 0; } It will indefinitely block until you provide an EOF on the terminal (or have some other EOF'ed data written to STDIN for the program, i.e. via a pipe). Sending signals (apart from SIGIO -- 23) instantly kills the program as nothing's masked. SIGIO not killing the program is to be expected as per signal(7) and fcntl(2)'s manpage descriptions. Tested on an FC7 machine, so your mileage on a FreeBSD machine may differ. Cheers, -Garrett
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?477D3E25.4080807>