- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Intermittent problem with BAD FILE NUMBER errno 9
Categories
Company
Local Language
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
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
Community
Resources
Forums
Blogs
- 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-29-2005 07:24 AM
тАО08-29-2005 07:24 AM
Intermittent problem with BAD FILE NUMBER errno 9
- Tags:
- write
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-29-2005 07:33 AM
тАО08-29-2005 07:33 AM
Re: Intermittent problem with BAD FILE NUMBER errno 9
Well. errno=9 is EBADF and that will be returned for an invalid file descriptor; viz. The 'fildes' argument to the write() is not a valid file descriptor open for writing.
...JRF...
- Tags:
- EBADF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-29-2005 07:40 AM
тАО08-29-2005 07:40 AM
Re: Intermittent problem with BAD FILE NUMBER errno 9
Either a file descriptor refers to no open file, or a read (resp. write)
request is made to a file that is open only for writing (resp. reading).
If the file is open is it growing beyond your ulimit? Just a guess.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-29-2005 09:30 PM
тАО08-29-2005 09:30 PM
Re: Intermittent problem with BAD FILE NUMBER errno 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-30-2005 02:50 AM
тАО08-30-2005 02:50 AM
Re: Intermittent problem with BAD FILE NUMBER errno 9
Here's the partial
code: Please note that error_file is declared an extern in the main program and is set to a 1.
===============================================================
#include
#include
#include
#include
#include
#include
extern int debug;
char ErrorFile[70];
extern char *pgm_name;
int error_file;
void
error_proc(const char *in_mess)
{
int mess_sz;
int err_fd;
static int the_top = 1;
if (debug)
(void)fprintf(stderr, "%s: in_mess = %s\n", pgm_name, in_mess);
if (error_file == 1)
{
mess_sz = strlen(in_mess);
if (the_top)
{
if ((err_fd = open(ErrorFile, O_WRONLY | O_CREAT, 0666)) < 0)
{
(void)fprintf(stderr, "%s: Error in opening the Error File %s errno = %d\n", pgm_name, ErrorFile, errno);
return;
}
the_top = 0;
}
else
{
if ((err_fd = open(ErrorFile, O_APPEND, 0666)) < 0)
{
(void)fprintf(stderr, "%s: Error in opening the Error File %s errno = %d\n", pgm_name, ErrorFile, errno);
return;
}
}
if (write(err_fd, in_mess, mess_sz) != mess_sz)
{
(void)fprintf(stderr, "%s: Error in writing to the Error File %s errno = %d\n", pgm_name, ErrorFile, errno);
(void)close(err_fd);
return;
}
(void)close(err_fd);
}
else
(void)fprintf(stderr, "%s: %s\n", pgm_name, in_mess);
return;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-30-2005 05:31 AM
тАО08-30-2005 05:31 AM
Re: Intermittent problem with BAD FILE NUMBER errno 9
if (write(err_fd, in_mess, mess_sz) != mess_sz)
and could it be returning a value greater than -1 but less than mess_sz, like mess_sz -1?
Can you change the test to be != -1 and then print errno? I think that the value of errno is undefined unless the write returns a -1 to signify failure. If the write is successful, you shouldn't be checking errno.....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-30-2005 06:44 AM
тАО08-30-2005 06:44 AM
Re: Intermittent problem with BAD FILE NUMBER errno 9
for my own private programming I use perror instead of reading errno.
e.g.:
if ((sf=open(argv[1],O_RDONLY)) == -1)
{
perror("open ");
return EXIT_FAILURE;
}
prints the systems error message.
Hope this helps!
Regards
Torsten.
__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.
__________________________________________________
No support by private messages. Please ask the forum!
If you feel this was helpful please click the KUDOS! thumb below!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-30-2005 08:15 PM
тАО08-30-2005 08:15 PM
Re: Intermittent problem with BAD FILE NUMBER errno 9
1) All the characters you asked it to write were written in one go. write() will return the number of characters you asked it to write.
2) Some (but not all) of the characters you asked it to write were written. i.e. a partial write. this can happen if the write() was interrupted by say a signal. It isn't an error, but you haven't written all the data, you must write the remaining data in subsequent write() operation(s). write() will return the actial number of characters written, which will be less than what you asked it to write.
3) An error occurred. write() will return -1 and set errno to indicate the error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-31-2005 12:35 AM
тАО08-31-2005 12:35 AM
Re: Intermittent problem with BAD FILE NUMBER errno 9
according to the posting above you may have a look at this "well known" procedure.
Maybe this is helpful in this case
________________________________
int writen (int fd,char * ptr, int nbytes)
{
int nleft,nwritten;
nleft=nbytes;
while (nleft > 0)
{ nwritten=write(fd,ptr,nleft);
if (nwritten <= 0)
return (nwritten); /* error or EOF */
nleft-=nwritten;
ptr+=nwritten;
}
return (nbytes-nleft);
}
Hope this helps!
Regards
Torsten.
__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.
__________________________________________________
No support by private messages. Please ask the forum!
If you feel this was helpful please click the KUDOS! thumb below!
