From what I can understand, on Mac OS X, daemon is something running in the background (same as Windows Service). Can I make the connection between daemon by saying that a dameon written in Java is considered to be a JVM? I read some where people mentioned about daemon thread and jvm thread, how are they related?
Share
No. A JVM — Java Virtual Machine — is the executable that runs your java program. A daemon is any program that runs without being attached to a particular terminal, like, oh, launchd.
So consider running a java program from the command line: the jar file is myapp.jar and you type
That starts an executable program at the path
/usr/bin/java, which is just a regular program. It just happens to be one that includes the interpreter for java instructions, the “java virtual machine“. It runs and simulates that special abstract java machine, and runs until all the normal threads of the java program terminate. It then returns a return code and ends. Since that java process was launched by the shell, it’s a child program of the shell, and the shell gets back a notice that it completed.Now, it’s possible to write a program, for example in C, that creates a process that isn’t owned by a shell; its parent becomes the process with process ID 1, which is called init(1) on most UNIX systems, or launchd on Mac OS/X. A process that is owned by PID 1 runs until it’s either stopped by a shutdown command, or it terminates itself (or crashes.)
Those processes are called daemons after the more-than-human spirits in Greek mythology. They’re called that because (a) it’s a cute name; (b) they have “supernatural powers” compared to a regular user program; and (c) old time hackers like cute names.