0

Here are some of the steps for creating a daemon process from a given process,

  • the given process exists soon after forking a child,

  • the child calls start a new session and also a new group, by setsid()

But I seem to find cases with only the first step without the second step:

What is the purpose of only having the first step without the second step?

Does it not want to create a daemon but something else?

Thanks.

Tim
  • 101,790

1 Answers1

0

The purpose, on high level, is best seen in the bash example that you gave. When, in an interactive bash shell, a normal user types ls, what happens is

  • Bash forks
  • the child process execs ls
  • when ls is finished, the child process ends

It would be silly to daemonize ls, because (in general) it ends very quickly.

Furthermore, it would also be strange is all processes that are forked from a shell would do a setuid(). You would then not be able to run a shell as a normal user.

Do not take the specifics of daemons as the general rule for the use of fork/exec.

Tim
  • 101,790
Ljm Dullaart
  • 4,643