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++
  • » Deaamonizzing problem

#1 2008-05-01 05:38 PM

reggler
Member
Registered: 2008-05-01
Posts: 3

Re: Deaamonizzing problem

Offline

#2 2008-05-01 06:29 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: Deaamonizzing problem

What exactly is your problem? Could you be more specific?
What happens after startup, is the daemon running or did
all processes quit? Or is the child process "stuck"?

You mention GPIO, are you working on an embedded OS,
if so which one? It might not be POSIX compliant or have
other strange quirks.

Offline

#3 2008-05-01 07:16 PM

reggler
Member
Registered: 2008-05-01
Posts: 3

Re: Deaamonizzing problem

Offline

#4 2008-05-01 07:49 PM

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

Re: Deaamonizzing problem

You should probably use _exit() instead of exit()...  Also, you probably should fork()
one more time after doing setsid(), to lose your session-leader status and ensure you
can't accidentally regain a controlling tty...  (And, you'll want to ignore SIGHUP while
doing so, to make sure your child process doesn't get hit with SIGHUP when the
session-leader parent exits...)

However, I don't know if any of that is related to your particular problem...

(Also, there is no "C++" tag here; use the "code" tag instead...)

Offline

#5 2008-05-01 08:56 PM

reggler
Member
Registered: 2008-05-01
Posts: 3

Re: Deaamonizzing problem

pid = fork();
	if (pid < 0)
	{
		_exit(EXIT_FAILURE);
	}
	else if (pid > 0)
	{
		_exit(EXIT_SUCCESS);
	}
	
	umask(0);

	sid = setsid();

Offline

#6 2008-05-01 10:22 PM

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

Re: Deaamonizzing problem

Offline

#7 2008-05-01 10:53 PM

Nope
Administrator
From: Germany
Registered: 2004-01-24
Posts: 385
Website

Re: Deaamonizzing problem

I there.

Why don't you just use the

daemon(1,1);

command? That does exactly that, getting your program into deamon mode. The two values are flags telling if you still need to keep a connection to the starting terminal (for printing some stats on startup for example).

Offline

  • Index
  • » C++
  • » Deaamonizzing problem

Board footer

Powered by FluxBB