当前位置: 技术问答>linux和unix
sco是否支持进程间传描述符?
来源: 互联网 发布时间:2014-12-17
本文导语: sco是否支持进程间传描述符?我按照清华大学出版社的UNIX网络编程第一卷,写了个子进程预先启动,父进程ACCEPT后把SOCKET传给空闲的子进程。可是每次sendmsg报Bad file number,请问SCO支持进程间传描述符吗?如果支持...
sco是否支持进程间传描述符?我按照清华大学出版社的UNIX网络编程第一卷,写了个子进程预先启动,父进程ACCEPT后把SOCKET传给空闲的子进程。可是每次sendmsg报Bad file number,请问SCO支持进程间传描述符吗?如果支持如何处理?
|
我不太清楚你的需求,但是一般这样的设计可以采用先fork几个子进程,这些子进程处理接收的请求,他们只处理请求,而不向请求者返回数据,接收发送数据都由父进程完成,父子进程可以通过ipc实现数据通信,这样做,我想可以完成你的要求,很多服务器就是这样做的,解决问题的方法很多,呵呵
|
>>对于文件描述符,在unix和linux的多进程体制下是只能传值,不能使用。要想使用,必须在获得文件局并后,通过fork方式传给子进程
no. i can't agree with you. as the book UNIX NETWORK PROGRAMMING says,a process can send a file descriptor to another process through a unix domain socket. this means the process that accepts the discriptor can use it as if it's opened( either using open() or socket()/accept,etc.) by itself. otherwise if it doesn't mean this,that is,it means one processs can only send the value of a file discriptor( perhaps some more related data) to another process but the target process can not use it as a normal file descriptor. then why the author wastes so many words merely to say such a obvios fact: a process can send data through a socket? but it may be true that on some platform(sco os e.g.) descriptor passing may not work.
that is only my logical conclusion. i'll try to verify it by facts.
no. i can't agree with you. as the book UNIX NETWORK PROGRAMMING says,a process can send a file descriptor to another process through a unix domain socket. this means the process that accepts the discriptor can use it as if it's opened( either using open() or socket()/accept,etc.) by itself. otherwise if it doesn't mean this,that is,it means one processs can only send the value of a file discriptor( perhaps some more related data) to another process but the target process can not use it as a normal file descriptor. then why the author wastes so many words merely to say such a obvios fact: a process can send data through a socket? but it may be true that on some platform(sco os e.g.) descriptor passing may not work.
that is only my logical conclusion. i'll try to verify it by facts.
|
父进程可以将文件描述符传递给子进程的。你的问题在于fork的子进程太多了,所以系统就没有资源再创建进程了。
如果仅仅是一个终端发数据,可以尝试用长连接。这样可以节省资源啊。
如果仅仅是一个终端发数据,可以尝试用长连接。这样可以节省资源啊。
|
如果是这样,改变一下设计
使用process pool,这样应该可以避免这个问题
使用process pool,这样应该可以避免这个问题
|
同意blh(老猫) 的,只传递描述符是不对的,进程间的地址空间是独立的,维护各自的FCBs。如果用线程,就可以只传描述符。