Then look at the process information on the other terminal again. Now return to the terminal where you are running your application and press Enter to invoke the _daemon function. You can see that the parent process of your application is the shell as expected. The application is running in the foreground When you look at the STAT field, you see that your process is running but waiting for an off-schedule event to occur which will cause it to run in the foreground. ps -C test -o "pid ppid pgid sid tty stat command" In this case, the _daemon function has not been called yet. Here, you'll have to use the ps command to get process-related information. You can see that the values related to your process are as follows. Run the application and switch to a different terminal without pressing any other keys. Now compile the application with the following command and examine the status of the process before and after _deamon is called: gcc -o test test. In this case, your new process will be a subprocess of init and will continue to run in the background. In the code above, _daemon creates a child process and then kills the parent process. To create a daemon, you need a background process whose parent process is init. Pid = fork() // Fork off the parent process
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |