- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- file descriptor of socket
Operating System - HP-UX
1821584
Members
3393
Online
109633
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2003 06:39 PM
тАО03-25-2003 06:39 PM
file descriptor of socket
Hi,
File descriptor from socket is always 1. It indicate the standard output.
After called socket and bind (socket fd,...)
listen will receive many stdout messages and not working well.
So,is there any solution to get another file descriptor without 1 from socket?
I'm using HP-UX 11.0
Toyomi
File descriptor from socket is always 1. It indicate the standard output.
After called socket and bind (socket fd,...)
listen will receive many stdout messages and not working well.
So,is there any solution to get another file descriptor without 1 from socket?
I'm using HP-UX 11.0
Toyomi
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2003 11:59 PM
тАО03-25-2003 11:59 PM
Re: file descriptor of socket
Hello,
I think you must have some bug in you code.
A call to socket will return the next
free file-descriptor and this should never be 1, at least not in a c-program.
Regards
Olav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2003 03:59 AM
тАО03-26-2003 03:59 AM
Re: file descriptor of socket
Hi
Olav is quite right, but...
socket() (and open() also) returns always the lowest possible descriptor (that is not being currently open).
So, if earlier in your code you closed fileno=1 it is first to be reused, as it means that connection with stdout was shut for good. Moreover because of this specification the system is oblidged to return 1, as it is the lowest possible descriptor.
The optimistic conclusion is that everything should work properly with descriptor 1, as it doesn't matter for socket.
But remember that all functions that write to stdout use fileno=1 hardcoded, so you MUST NOT call any of such, as it will write to your socket.
So if you aware of such situation you have two possibilities:
1. Keep fileno=1 open. Either do not close it or open it afterwards.
2. Use dup() function to use another fileno and close original fileno=1 (However I've never tried this on sockets and manuals do not say a word about it. I guess you should do it just after socket(), before bind(), if it works at all).
However if you have stdout closed I assume your process daemonized and, as a daemon, it shouldn't perform any writing to stdout.
Good luck
Adam
Olav is quite right, but...
socket() (and open() also) returns always the lowest possible descriptor (that is not being currently open).
So, if earlier in your code you closed fileno=1 it is first to be reused, as it means that connection with stdout was shut for good. Moreover because of this specification the system is oblidged to return 1, as it is the lowest possible descriptor.
The optimistic conclusion is that everything should work properly with descriptor 1, as it doesn't matter for socket.
But remember that all functions that write to stdout use fileno=1 hardcoded, so you MUST NOT call any of such, as it will write to your socket.
So if you aware of such situation you have two possibilities:
1. Keep fileno=1 open. Either do not close it or open it afterwards.
2. Use dup() function to use another fileno and close original fileno=1 (However I've never tried this on sockets and manuals do not say a word about it. I guess you should do it just after socket(), before bind(), if it works at all).
However if you have stdout closed I assume your process daemonized and, as a daemon, it shouldn't perform any writing to stdout.
Good luck
Adam
I do everything perfectly, except from my mistakes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2003 04:20 AM
тАО03-26-2003 04:20 AM
Re: file descriptor of socket
Hi,
I think that Adam is really right, but rather than dup'ing the socket file descriptor, I would add two dummy 'open' (open /dev/null for example) to be sure that you won't use stdout and stderr also and finally get a file descriptor greater than 2.
Regards.
I think that Adam is really right, but rather than dup'ing the socket file descriptor, I would add two dummy 'open' (open /dev/null for example) to be sure that you won't use stdout and stderr also and finally get a file descriptor greater than 2.
Regards.
It works for me (┬й Bill McNAMARA ...)
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP