Demonic and non-demonic processes

We have already studied what demonic and non-demonic threads are. The same principle applies to processes as well. A demonic process runs in the background without blocking the main process, while a non-demonic process runs in the foreground. This is shown in the following example:

It can be seen from the preceding code snippet that when we create and execute a non-demonic process (the default option) as shown in output 1 and in line 20, after printing Main Ended, the Terminal window halts for 4 seconds while waiting for the non-demonic process to finish its execution. When it finishes, we get the Exit Non Daemonic message, which is when the main program exits. In the second case (shown in output 2), the main program does not wait for the demonic process to finish its execution. The daemonic process runs in the background and by the time it is finished, the main thread has already exited from the memory. For this reason, we did not see the Exit :Daemonic message printed on the screen.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.70.93