Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 May 1997 06:30:33 -0500 (CDT)
From:      Alec Kloss <alec@d2si.com>
To:        chaos@tgci.com
Cc:        questions@FreeBSD.ORG
Subject:   Re: (Fwd) (Fwd) File descriptors-do I have Bad Breath?
Message-ID:  <199705131130.GAA01665@d2si.com>
In-Reply-To: <199705130243.TAA00297@train.tgci.com> from "Riley J. McIntire" at "May 12, 97 07:15:25 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
Riley, I've tried to answer you questions best I could...

Riley J. McIntire is responsible for:
> From owner-freebsd-questions@FreeBSD.ORG Mon May 12 22:21:03 1997
> Message-Id: <199705130243.TAA00297@train.tgci.com>
> Comments: Authenticated sender is <chaos@mail.tgci.com>
> From: "Riley J. McIntire" <chaos@mail.tgci.com>
> To: questions@FreeBSD.ORG
> Date: Mon, 12 May 1997 19:15:25 +0000
> Subject: (Fwd) (Fwd) File descriptors-do I have Bad Breath?
> Reply-to: chaos@tgci.com
> Priority: normal
> X-mailer: Pegasus Mail for Win32 (v2.42a)
> Sender: owner-questions@FreeBSD.ORG
> X-Loop: FreeBSD.org
> Precedence: bulk

> Ok, I know when I'm beat!  Must be the way I comb my hair!
> 
> ------- Forwarded Message Follows -------
> From:          "Riley J. McIntire" <chaos@mail.tgci.com>
> To:            freebsd-fs@FreeBSD.ORG
> Date:          Sun, 11 May 1997 12:17:16 +0000
> Subject:       (Fwd) File descriptors-do I have Bad Breath?
> Reply-to:      chaos@tgci.com
> Priority:      normal
> 
> Apologies if this is off-topic for freebsd-fs, but I either have very 
> bad breath or am asking silly questions that don't deserve to be 
> answered on Questions.
> 
> Could someone take a look at my questions and at least tell me which 
> manual RTFM refers to?  :)
> 
> ------- Forwarded Message Follows -------
> From:          Self <chaos>
> To:            questions@FreeBSD.ORG
> Subject:       File descriptors
> Reply-to:      chaos@tgci.com
> Date:          Sat, 10 May 1997 13:27:28
> 
> I'm getting some bad file descriptor errors that prevented me from 
> compiling a new kernal (I'm new...), and got some help here about 
> that. 
	A "Bad file descriptor" message corresponds error EBADF.
	You can look up some details on errors by typing
	man errno.  Here's the section for EBADF:

 9 EBADF Bad file descriptor. A file descriptor argument was out of range,
         referred to no open file, or a read (write) request was made to a
         file that was only open for writing (reading).        

	So, a "Bad file descriptor refers to a illegal file
	descriptor used in a program.  This is likely to
	happen if the open of a file fails and the caller
	of open(2) doesn't check to make sure the file was
	opened before trying to use it.  Which leads us up
	to your next question about file descriptors
	themselves.
> 
> But I'm not clear about what causes bad file descriptors or even 
> what they are/do.
> 
	A file descriptor is a small integer number
	(usually between 0 and 50, if not 0 and 10) used to
	reference a file (or other device) after being
	opened.  Typical usage in a C program is something
	like this:

		/* ... */
		{
		int fd;
		fd = open ("/tmp/mytempfile", O_RDWR);
		if (fd == -1) {
		    fprintf (stderr, "Unable to open "
		      "/tmp/mytempfile: %s", 
		      strerror (errno));
		    exit (1);
		  }
		write (fd, "Hello World", 
		  strlen ("Hello World"));
		close (fd);
		exit (1);
		}

	If you are not a C programmer, this will not make
	much sense, but I'll try to describe what is going
	on.  The system call open(2) is made, attemping to
	open the file /tmp/mytempfile in read/write mode.
	If successful, open returns a non-negative descriptor 
	(a small number) for the process to use when 
	referencing the file.  If open(2) fails, it returns
	-1, which is typical unix convention.  

> I've searched  the docs, man hier, man fd and am still not clear.  Do 
> they indicate the state a file is in?  Open, writable, locked?  What 
> constitutes a bad one?  Is it caused by bad hardware?  Disks?  
> Controllers?
	So no, bad file descriptors are not caused
	(directly) by disks.  In fact, you can get bad file 
	descriptor messages when working with non-disk 
	related things, such as sockets.  It is much more 
	likely that you are hitting some configured-in limit 
	of your system.  Try typing 
		limit
	at a csh prompt and checking the limit on
	descriptors (or openfiles).  You may be able to
	raise it with
		limit descriptors 200
	or something like it.  (200 is just an example 
	and is perhaps to high.)
> 
> I'm had stuff like this on more that one occasion:
> 
> find: /usr/include/machine: Bad file descriptor
> find: /usr/src/gnu/usr.bin/cc/cc_int/loop.c: Bad file descriptor
> find: /usr/src/gnu/usr.bin/cc/cc_int/obstack.c: Bad file descriptor
> etc
> 
> Last time I had to use clri and some other stuff to fix it.  fsck 
> doesn't take care of it.
> 
> I am going to replace the IDE 1.2GB Maxtor with a Seagate scsi for 
> this low volume webserver( and move it from 2.1.7 to 2.2.1--a good 
> idea???). 
> 
> Will this fix the cause?  Is a bad disk causing this?  I haven't done 
> a low-level format, but plan on it later.  Should/will this show up 
> anything?
> 
> Could someone explain or point me to some documentation on this?
> 
> Ciao,
> 
> Riley
> 
> 

For more information on unix system calls, etc., you may want to try 
	"Advanced Programming in the UNIX Environment" 
	by W. Richard Stevens (published by Addison-Wesley)
I've also had recommended to me
	"The Design of the UNIX Operating System"
	by M.J. Bach (published by Prentice-Hall)
although I've never read it.  

Hope this helps.  I'd guess most people who read your first postings
assumed someone else would answer.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199705131130.GAA01665>