I researched the Linux kernel code (2.6.11) about the creation of a process/thread, and followed do_fork()->alloc_pidmap()
It seems that alloc_pidmap always returns pid > 300 once the previous pid’s ever reached the max pid, while actually daemon’s pid is always < 300 (Is this correct?).
Does a daemon obtain its pid using a function other than alloc_pidmap()? If so, does it imply the daemon process is not created using do_fork?
AFAIK pid are allocated by the kernel; the limit of 300 (i.e.
#define RESERVED_PIDS 300private insidekernel/pid.c) you are seeing is perhaps because on most systems, several processes have been forked early in the bootstrap (e.g. frominitrdperhaps).You could test by booting from GRUB directly into a kernel with
init=/bin/shSome processes are kernel processes (without userland code, e.g.
kworkerorkauditd), which are not started by fork from init or descendants. They are probably started withkthread_createinside the kernel (and without any syscall).And you should explain why are you asking that. Is your question about determining if a process is a deamon or not?