- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Curious case of HPUX popen!
Operating System - HP-UX
1748051
Members
5034
Online
108758
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
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
Go to solution
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
тАО08-17-2009 10:21 PM
тАО08-17-2009 10:21 PM
I have a interesting case with popen and file descriptors in HPUX.
Attached are two sample "C" programs (a parent calling a child with popen). The parent opens a socket and "popens" the child program, which does a fstat/getsockname on the socket fd passed from the parent.
Funny thing is all socket descriptors except fd's 24-29 works fine. If the parents socket fd is between 24-29, then the child does not see that as a open fd at all. (I traced the system calls and seems like popen is closing fd 24-29, ie, treating these few fd's in a special way).
Does anyone have any info about this? Is this a bug? Since this behavior of popen seems to defy posix standards!
(BTW - i did a regular cc to compile these programs on hpux, where it fails. It works fine on all other unixes i tried - linux, solarix, aix etc)
Thanks in Advance.
- Subhasis
Attached are two sample "C" programs (a parent calling a child with popen). The parent opens a socket and "popens" the child program, which does a fstat/getsockname on the socket fd passed from the parent.
Funny thing is all socket descriptors except fd's 24-29 works fine. If the parents socket fd is between 24-29, then the child does not see that as a open fd at all. (I traced the system calls and seems like popen is closing fd 24-29, ie, treating these few fd's in a special way).
Does anyone have any info about this? Is this a bug? Since this behavior of popen seems to defy posix standards!
(BTW - i did a regular cc to compile these programs on hpux, where it fails. It works fine on all other unixes i tried - linux, solarix, aix etc)
Thanks in Advance.
- Subhasis
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2009 01:42 AM
тАО08-18-2009 01:42 AM
Solution
>Does anyone have any info about this? Is this a bug?
Not really, it is fully documented. You shouldn't be using popen(3) but fork(2), exec(2) and pipe(2) directly, if you are going to be this tricky.
>I traced the system calls and seems like popen is closing fd 24-29,
If you look closely, you'll see that it is the posix shell that is closing them as documented: sh-posix(1):
WARNINGS
Some file descriptors are used internally by the POSIX shell. For HP-UX releases 10.10 and beyond, file descriptors 24 through 30 are reserved. Applications using these and forking a subshell should not depend upon them surviving in the subshell or its descendants.
Any reason you fclose stdout in the child? It's probably better to just fflush(3).
Not really, it is fully documented. You shouldn't be using popen(3) but fork(2), exec(2) and pipe(2) directly, if you are going to be this tricky.
>I traced the system calls and seems like popen is closing fd 24-29,
If you look closely, you'll see that it is the posix shell that is closing them as documented: sh-posix(1):
WARNINGS
Some file descriptors are used internally by the POSIX shell. For HP-UX releases 10.10 and beyond, file descriptors 24 through 30 are reserved. Applications using these and forking a subshell should not depend upon them surviving in the subshell or its descendants.
Any reason you fclose stdout in the child? It's probably better to just fflush(3).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-19-2009 10:30 PM
тАО08-19-2009 10:30 PM
Re: Curious case of HPUX popen!
Hi Denis,
Many thanks much for your detailed and informative reply. This really solves the perplexing question that was bugging me.
Best Regards,
Subhasis
Many thanks much for your detailed and informative reply. This really solves the perplexing question that was bugging me.
Best Regards,
Subhasis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-19-2009 10:31 PM
тАО08-19-2009 10:31 PM
Re: Curious case of HPUX popen!
Dennis's reply answers my query completely. So closing this thread.
- Subhasis
- Subhasis
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.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP