UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C++
  • » Writing daemon in C++

#1 2009-10-18 10:04 PM

tomcio
Member
From: Poland
Registered: 2006-08-14
Posts: 113

Re: Writing daemon in C++

Hello!

I'm working on some kind of UNIX daemon in C++. My server isn't a regular daemon (it's not launched by init process but by normal users (mostly) in their X sessions), so it share so similarities with unix daemons.

I have problem with initializing my daemon. Usually in child processes created by fork() we close all standard I/O streams (stdout, stdin, stderr). I how to do it with C library, but I'm not sure what to do with I/O streams from standard C++ library.

I don't know how to close cin, cout, clog and cerr streams...

Offline

#2 2009-10-19 12:55 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,833
Website

Re: Writing daemon in C++

You don't need to care about the higher-level streams, anymore than you need to
care about the stdio FILE pointers in plain C...  Just close the low-level file descriptors,
and/or reopen "/dev/null" on top of them, the same as you would in C...

Offline

#3 2010-08-14 10:35 PM

vgupta
Member
Registered: 2010-08-12
Posts: 3

Re: Writing daemon in C++

Here's a simple implementation to create a Daemon
Creating a Daemon in Linux

Offline

#4 2010-08-15 10:34 AM

tomcio
Member
From: Poland
Registered: 2006-08-14
Posts: 113

Re: Writing daemon in C++

Interesting link, thank you

Offline

  • Index
  • » C++
  • » Writing daemon in C++

Board footer

Powered by FluxBB