Derek
Derek

Reputation: 11915

issues with select() statements

I have a program that is using select() to poll for a socket ready to be connected.

I have another program that binds to a socket and issues send() commands.

The question I have is if the file descriptors work across two executables like that.

i.e. if I add file descriptor 5 in program A to the FD_SET, and my socket fd in program B is 5, does this mean that send() on that socket will wake up program A that is doing a select on the FD_SET containing 5?

Thanks

Upvotes: 1

Views: 115

Answers (3)

Viswesn
Viswesn

Reputation: 4880

Mostly 1024 descriptors (file/ socket) were supported by a given process (0-1023) (See the max limit of file/ socket descriptor supported by process in /proc//limits).

First 3 descriptors (0, 1 and 2) were assigned to stdin, stdout and stderr respectively. The next descriptor with value 3 will be assigned to the next open file / socket descriptors and can go till the limit specified in /proc. Note: You can also change the max supported descriptor.

You can see the list of file descriptors open by a given process in /proc//fd. Each process descriptor / signal / event scope is specific to process only.

Upvotes: 0

Marco Leogrande
Marco Leogrande

Reputation: 8458

No, file descriptor numbers are process-specific. Using the same fd number across different processes has no implicit effect.

Upvotes: 2

user207421
user207421

Reputation: 310893

It has nothing to do with file descriptor numbers.

If you send via a socket over a connection whose other end is a socket that is being selected on for reads, the selector will detect the read event.

Upvotes: 0

Related Questions