linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Glynn Clements <glynn.clements@virgin.net>
To: Sindunata <software@dygsp.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: simple daemon dies
Date: Wed, 29 May 2002 10:29:36 +0100	[thread overview]
Message-ID: <15604.40832.369590.75158@cerise.nosuchdomain.co.uk> (raw)
In-Reply-To: <20020529153938.A4699@top4>


Sindunata wrote:

> I'm trying to write a simple daemon background process.
> It connects to PostgreSQL and wait for a notify event and upon receiving
> some event will invoke some URL using curl library.
> 
> I got it working already if I run it in foreground. But if I put the
> process in background (using &), and then after sometime the process
> will die.

In which case, the shell will tell you why it died.

Exited normally with zero status:

	[1]+  Done                    prog

Exited normally with non-zero status:

	[1]+  Exit 1                  prog

Terminated due to SIGTERM:

	[1]+  Terminated              prog

Terminated due to SIGIOT (aka SIGABRT):

	[1]+  Aborted                 (core dumped) prog

Terminated due to SIGKILL:

	[1]+  Killed                  prog

... and so on.

> I think there's some signal that I need to catch, can
> someone please help me?

You don't necessarily *need* to catch any signals. Most of the signals
which terminate a process (e.g. SIGHUP, SIGTERM, SIGINT) are *meant*
to terminate the process. When a program catches one of these signals,
it's normally so that it can "clean up" before it terminates, not to
prevent termination altogether.

> Currently i'm trapping the following signals:

>   sigaction (SIGTERM, &act, NULL);
>   sigaction (SIGINT, &act, NULL);

These are meant to kill the process; there's no reason to catch them.

>   /* ignore SIGHUP  & SIGTTOU */
>   act.sa_handler = SIG_IGN;
>   sigaction(SIGHUP, &act, NULL);

Same here.

>   sigaction(SIGTTOU, &act, NULL);

This will only stop the process, not terminate it.

If you're trying to write a daemon (as opposed to simply running in
the background), the process should be entirely disassociating itself
from the terminal and from the process group, so it shouldn't be
affected by terminal-related signals.

-- 
Glynn Clements <glynn.clements@virgin.net>

  reply	other threads:[~2002-05-29  9:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-29  8:39 simple daemon dies Sindunata
2002-05-29  9:29 ` Glynn Clements [this message]
2002-05-30  2:16   ` Sindunata
2002-05-30  5:24     ` Glynn Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15604.40832.369590.75158@cerise.nosuchdomain.co.uk \
    --to=glynn.clements@virgin.net \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=software@dygsp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).