码迷,mamicode.com
首页 > 系统相关 > 详细

fork() in linux

时间:2014-06-07 21:47:58      阅读:443      评论:0      收藏:0      [点我收藏+]

标签:des   c   class   code   a   http   

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,布布扣,bubuko.com

fork() in linux

标签:des   c   class   code   a   http   

原文地址:http://www.cnblogs.com/wxz888/p/3774817.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!