-1

I am having a problem in daemonize program. The problem is after closing all the opened descriptors, i need to reopen the stdout file to print the message.

I am having one way. But that is not working.

The way is duplicate the stdout descriptor using dup and reopen that. But the deamonize function is called it closes all the file descriptors. So, that duplicate file descriptor is also closed.

Can anyone please help me to do that.

10
  • 1
    Why do you want to print to stdout in a daemon?
    – P.P
    Jan 18, 2016 at 11:18
  • I want to check the program is running only once(single instance daemon). So, if it is already executed i need to print the error message in terminal.
    – user5443453
    Jan 18, 2016 at 11:19
  • This question may be related to this other question
    – Magix
    Jan 18, 2016 at 11:25
  • 1
    @msc, It is not that question. My requirement is after closing all the file descriptors, i need to open the stdout file.
    – user5443453
    Jan 18, 2016 at 11:27
  • 1
    It is not working. It gives the error "no such devices or address".
    – user5443453
    Jan 18, 2016 at 11:29

1 Answer 1

1

If you use daemon() to daemonize, you can specify noclose to prevent these filedescriptors from being closed:

daemon(0, 1);

But you should close these after your check by hand, otherwise your terminals might get messed up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.