由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - Re: how to close port/socket from parent process?help!!!!!!!!!
相关主题
[转载] why need dup?how to fork a subroutine in unix?
a difficult questionhow to record the process end time in a child process and obtain it in the parent process?
什么命令可以查看sockets端口的占用情况?(null)thx有没有什么工具可以显示哪个process占用了哪些port?
A question about thread of unixfork() and execve() in Unix
a question about inetd server programmingQuestion on file descriptor
help! cannot bind to socket!"fork" program question.
Is it possible to bind several sockets to 1 port?file descriptor
simple simple questionfileID
相关话题的讨论汇总
话题: fd话题: process话题: socket话题: parent话题: port
进入Unix版参与讨论
1 (共1页)
m*****e
发帖数: 4193
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.
d***j
发帖数: 25
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.

c**t
发帖数: 38
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.这样我们也许就可以在子进程里进行必要的操作。
: 么办哪?急
: 谢谢!

p******f
发帖数: 162
4

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,
*
* 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.这样我们也许就可以在子进程里进行必要的操作。
: 么办哪?急
: 谢谢!

d***j
发帖数: 25
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,
: *

1 (共1页)
进入Unix版参与讨论
相关主题
fileIDa question about inetd server programming
[转载] using ssh in tcsh scripthelp! cannot bind to socket!
link between file descriptor & pointer?Is it possible to bind several sockets to 1 port?
[转载] windows C++ -> Unix C++simple simple question
[转载] why need dup?how to fork a subroutine in unix?
a difficult questionhow to record the process end time in a child process and obtain it in the parent process?
什么命令可以查看sockets端口的占用情况?(null)thx有没有什么工具可以显示哪个process占用了哪些port?
A question about thread of unixfork() and execve() in Unix
相关话题的讨论汇总
话题: fd话题: process话题: socket话题: parent话题: port