fork() in linux

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:

[1] http://stackoverflow.com/questions/11733481/can-anyone-explain-a-simple-description-regarding-file-descriptor-after-fork

[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,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。