in reply to Re: daemon with Perl on Linux
in thread daemon with Perl on Linux

OK, now I am confused. When script is listening for the data on the socket, isn't STDIN whatever script receives from that socket? If so, then whenever I make the script to run as a daemon, I won't be able to receive anything on the socket since STDIN will be detached. Am I right? What I have is a script listening for the data on the socket, and I want that script to run in the background all the time and process whatever I get from that socket. By the way, how should I enable this daemon to run at startup? Is it enough just to add it to one of startup files, or should I use runlevel folders?... Thanks for the help.

Replies are listed 'Best First'.
Re^3: daemon with Perl on Linux
by Joost (Canon) on Nov 29, 2007 at 19:05 UTC
    STDIN is the name for one of the 3 standard file handles that a process inherits from its parent process. If you start a program from the command line without input redirection, STDIN is bound to the terminal, so that anything that's typed in at the terminal is delivered to the program via its STDIN handle.

    But you can also start programs with STDIN bound to something else:

    $ my-program < a-file # or $ some-program | some-other-program
    etc.

    In general when you open a socket you get/use a new filehandle especially for that socket, since even though it's possible to re-open STDIN in some other way later (through a socket or file or whatever) that would IMO just be confusing.

    Though most unix systems have a fairly similar ways to deal with startup/shutdown scripts through various runlevel files etc, the differences in how to administrate those files easily are different enough that you should probably just look up your system's documentation.

    If you want to become better informed about all these issues, I recommend Advanced Programming in the UNIX Environment (2nd edition).