0

I first tried to use the code in this question: Creating a daemon in Linux

But I got a SIGFAULT caused by a fgetc call.

I then tried int daemon(int nochdir, int noclose); function, and it seems perfectly working.

Also, using ps -xj, I can see the behaviour described in the answer of the linked question so it's really working as I wanted to).

What's the difference between the two ways?

Jonathan Leffler
  • 666,971
  • 126
  • 813
  • 1,185
Federico Ponzi
  • 2,347
  • 4
  • 30
  • 53
  • 1
    If your code is crashing because of a segmentation fault, it almost certainly means there's a bug of some sort in your code (not in the libraries). What file stream was the failing `fgetc()` using? Had you checked that the file stream pointer was valid? – Jonathan Leffler Sep 15 '15 at 19:29
  • You should post your code, it's not obvious which code you are using and where it calls fgetc. – David Grayson Sep 15 '15 at 19:31
  • There's no list of differences; it's a matter of deciding whether `daemon(3)` fits your needs or if you'll need to roll your own for some reason. Read the manpage. Rule of thumb: use `daemon(3)` unless you have a very good reason not to. If you have to ask this question, you probably don't want / need to roll your own daemonize function. – Filipe Gonçalves Sep 15 '15 at 19:34

0 Answers0