About fork() in linux:
parent/child processes created by fork() share the same file table (linux
file descriptor or called `open file descriptor`)
Which code will the new process execute?
Acutally they share the same code, the different is the return value of
fork();
for child process, fork() returns zero, but for parent process, the actual
child process id which is non-zero.
Reference:
[2] http://man7.org/linux/man-pages/man2/fork.2.html
About select() in linux:
select() and pselect() allow a program to monitor multiple file descriptors,
waiting until one or more of the file descriptors
become "ready" for some class of I/O operation (e.g., input possible). A file
descriptor is considered ready if it is possible
to perform the corresponding I/O operation (e.g., read(2)) without blocking.
My understanding:
In network programing like socket,read,write, there are two kinds of api,
readsync() or readasync(), one will bock if there is no data to read,
another will not block for it will test whether there is data to read. So in
the low level, `select` does this kind of thing!
Reference:
[1] http://linux.die.net/man/2/select
[2] http://stackoverflow.com/questions/14544621/why-is-select-used-in-linux
fork() in linux,布布扣,bubuko.com