ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
If that's not what you're looking for then you're really going to need to be a little more specific with your questions. It's hard to answer a question "What does this code mean?" Say right off what's confusing you about it and what you'd like to know.
Perhaps NOFILE is defines in a header you're including. It's not, to my knowledge, a standard ANSI C or POSIX macro. There is a MAX_OPEN_FILES or something similar defined in POSIX, but I don't think there's a NOFILE. In any case, if the program compiles, it's being defined somewhere, so check the header files included in the program.
The close system call does not terminate your program. That is done by returning from main, calling exit or (sometimes) _exit. What makes you think the close call is causing your program to terminate?
From 'Advanced Programming in the Unix Environment' on page 42:
A common sequence of code in a daemon process is one that closes all open files.
Some programs have the code sequence
for (i = 0; i < NOFILE; i++)
assuming the constant NOFILE was defined in the <sys/param.h> header.
Other programs use the constant _NFILE that some versions of <stdio.h>
provide as the upper limit.
For your own programs, use the POSIX.1 value OPEN_MAX to determine the maximum open files value portably.
This value may be indeterminate at compile time. Using the function call sysconf(_SC_OPEN_MAX) can also determine this value. The value is referred to as 'run-time invariant'. This means that it won't change during the lifetime of the process.