Redian新闻
>
Re: how to close port/socket from parent process?help!!!!!!!!!
avatar
Re: how to close port/socket from parent process?help!!!!!!!!!# Unix - 噫吁兮,危乎高哉
m*e
1
fcntl(fd, F_SETFD, FD_CLOEXEC) in your parent process, so this fd will be
closed automatically if you do exec in the child process.
avatar
d*j
2
问题是:
所有networking的细节全部不可见。从那个库函数看不到任何打开socket或file或某个port的调用。
也就是说我没法拿到那个"fd"
我就是要找到当前进程都打开了那些端口,或说在用哪些socket.这样我们也许就可以在子进程里进行必要的操作。
么办哪?急
谢谢!

【在 m*****e 的大作中提到】
: fcntl(fd, F_SETFD, FD_CLOEXEC) in your parent process, so this fd will be
: closed automatically if you do exec in the child process.

avatar
c*t
3

port的调用。
在子进程里进行必要的操作。
U can get them from Unix process descriptor data structure, as i remember
there has a pointer point to a file descriptor table which contains file
descriptors (include socket) opened by this process.
forget details, i have not do unix programming for 2 years.
u can check process management related Unix System Data Structure.
the
networking
some
conflicts
parent.
used to

【在 d***j 的大作中提到】
: 问题是:
: 所有networking的细节全部不可见。从那个库函数看不到任何打开socket或file或某个port的调用。
: 也就是说我没法拿到那个"fd"
: 我就是要找到当前进程都打开了那些端口,或说在用哪些socket.这样我们也许就可以在子进程里进行必要的操作。
: 么办哪?急
: 谢谢!

avatar
p*f
4

easy, see the code
for (fd=0; fdstruct stat sbuf;
if (fstat(fd, &sbuf)==0 && (sbuf.st_mode & S_IMFT) == S_IFSOCK) {
/*
* this is a socket, do whatever you want,
* in your case, you may want to set fd to close-on-exec,
* please check microbe's reply for how to do this,
*
* if you want to get the server addr and port of this scoket,
* call getpeername(), for local addr and port, call getsockname()
*/
}
}
check the manual for stat to

【在 d***j 的大作中提到】
: 问题是:
: 所有networking的细节全部不可见。从那个库函数看不到任何打开socket或file或某个port的调用。
: 也就是说我没法拿到那个"fd"
: 我就是要找到当前进程都打开了那些端口,或说在用哪些socket.这样我们也许就可以在子进程里进行必要的操作。
: 么办哪?急
: 谢谢!

avatar
d*j
5
Thanks a lot!
Will test it out ASAP
It looks reasonable

【在 p******f 的大作中提到】
:
: easy, see the code
: for (fd=0; fd: struct stat sbuf;
: if (fstat(fd, &sbuf)==0 && (sbuf.st_mode & S_IMFT) == S_IFSOCK) {
: /*
: * this is a socket, do whatever you want,
: * in your case, you may want to set fd to close-on-exec,
: * please check microbe's reply for how to do this,
: *

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。