Neither the above are actually entirely correct:
- True: The kernel is somewhat similar to a shared library. But there are difference. The kernel actually IS a program, with its own arguments (passed from the boot loader), though not a process in the traditional sense. Said program is responsible for initializing a privileged memory and execution space (Intel: Ring 0, ARM: SVC or EL1), wherein it has full access to hardware and can initialize subsystems, including memory management (through which it creates the isolated virtual memory containers we call "processes"), scheduling (for threads, which run inside processes) filesystems, and more.
BUT:
The kernel spawns quite a few threads of its own in its memory space (which you can easily see in Linux, for example, using ps -ef and looking for the PPID of 2, or ps aux looking for RSS/VSIZE of 0), and in newer version of ps, [ ] markers. Darwin (MacOS/iOS) cannot show kernel threads with built in tools unless a specialized sys call (presently, #491, stack_snapshot_with_config) is used.
ONE of the kernel threads (exactly which , depends on OS) , "germinates" and becomes the user mode PID 1 - init (now "systemd" on newer Linux systemd), or launchd (Darwin). This iS NOT some inexpensive infinite loop. It has enough on its plate, adopting orphan processes (reaping them and preventing zombies), starting up tasks, and generally housekeeping. PID 1 itself blocks most of the time, and is NOT to be confused with idle tasks (which are , in fact kernel threads). PID 1 is also immortal (can't kill with -9) and should it die hideously (by some exception), the kernel usually panics.
Explanation #2 (334403) is more on the mark, but kernel threads keep on executing in the background. e.g. Linux kswapd which may do swapping in response to certain page faults. Or scheduled flushing of page/buffer (Darwin:unified) caches. That said, other transitions to kernel mode are usually indeed on system call (voluntary), or interrupt/exception (non-voluntary). That is, unless one of the kernel threads wakes up and needs to do something.