All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sindunata <software@dygsp.com>
To: Glynn Clements <glynn.clements@virgin.net>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: simple daemon dies
Date: Thu, 30 May 2002 09:16:17 +0700	[thread overview]
Message-ID: <20020530091617.A10993@top4> (raw)
In-Reply-To: <15604.40832.369590.75158@cerise.nosuchdomain.co.uk>; from glynn.clements@virgin.net on Wed, May 29, 2002 at 10:29:36AM +0100

Hi Glynn & All,

Thanks for the explanation. I found the bug in my code:
  printf("%s", CURLreturn);
while it should be
  printf("%d", CURLreturn);

This cause a segmentation fault. Anyway when I tried running it in the
background and disconnect my terminal, it seems good now.

> 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.

Yupe, I'm catching those signals (SIGTERM & SIGINT) to cleanly and
politely :) disconnecting from postgresql only.

> >   /* 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.

I tought that I need to ignore SIGHUP & SIGTTOU so that my process is
not killed/stopped when I disconnect my terminal. CMIIW.

> 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.

This is exactly what I'd like to do, writing a daemon. I tought that
it's just a normal C program which catches some signal. I'm still a
novice in linux C programming. Perhaps someone would give me examples how
to disassociate from the terminal and process group.

TIA & best regards,
Sindu

  reply	other threads:[~2002-05-30  2:16 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
2002-05-30  2:16   ` Sindunata [this message]
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=20020530091617.A10993@top4 \
    --to=software@dygsp.com \
    --cc=glynn.clements@virgin.net \
    --cc=linux-c-programming@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.