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...
Given that 8592 & 0777 == 0620, while 8630 & 0777 == 0666, but neither case returns EBADF, I would guess that nohup actually opens /dev/null to 0 instead... and in fact, "strace nohup ls" gives: open("/dev/null", O_WRONLY|O_LARGEFILE) = 3 dup2(3, 0) = 0 close(3) = 0 umask(037777777177) = 022 open("nohup.out", O_WRONLY|O_CREAT|O_APPEND|O_LARGEFILE, 0600) = 3 dup2(3, 1) = 1 close(3) = 0 umask(022) = 0177 If that's what you want, you could check the major/minor device number in the result of fstat. However: 1) I think it's not portable to Windows (except Cygwin), though there you do not have to worry about nohup. 2) It would not distinguish nohup from "./foo < /dev/null" of course. Paolo