[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how do I check that an FD is open?
From: |
Bruno Haible |
Subject: |
Re: how do I check that an FD is open? |
Date: |
Sun, 14 Dec 2008 22:02:38 +0100 |
User-agent: |
KMail/1.9.9 |
Sam Steingold wrote:
> How do I figure out if the fd (specifically, stdin=0) is open?
> apparently it is closed when the application is run by nohup.
> the only thing I could figure out so far is fstat: when 0 is open,
> st_mode is 8592, when it is closed it is 8630...
When fd is closed, fstat should return -1 and set errno to EBADF. So your
test is
fstat (fd, &stbuf) < 0 && errno == EBADF.
Of course, Jim's trick with fcntl is even better, since it does not cause
disk or disk cache accesses.
Bruno