简体   繁体   中英

Exec() and Fork()

So i created ac program in unix. This is what it does.

1)It forks a process.

Child Process: Performs execv() on a alarm clock program which prints "Alarm rang" after 'x' seconds

Parent Process: Performs waitPID on child above. Then exits.

Output: So i ran it and i received the "Alarm rang after x seconds"

Everything is working fine. But now what i want is for the child process to run in the background. Meaning i do not want to see its output. but i want it to run and exit.

To make the child process run in the background, you need to make it a daemon process .

There are few steps to follow to make it a daemon process..

  1. Fork off the parent process
  2. Change file mode mask (umask)
  3. Open any logs for writing
  4. Create a unique Session ID (SID)
  5. Change the current working directory to a safe place
  6. Close standard file descriptors

For a better explanation, see this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM