Does dmesg
get kernel messages from the kernel ring buffer?
Yes, as described in man dmesg
:
dmesg
is used to examine or control the kernel ring buffer.
Does the kernel ring buffer store only messages generated by the kernel, not those by processes?
No, processes can add messages to the kernel ring buffer, by writing to /dev/kmsg
.
Where does dmesg
get user space messages?
From the kernel ring buffer, using either /dev/kmsg
or the syslog
system call (not to be confused with the syslog
system logger and associated services). Messages are distinguished by their “facility”; kernel messages use the kern
facility, user messages the user
, mail
, daemon
etc. facilities (see dmesg --help
for a list of supported facilities).
Do user space messages include those messages generated by all the processes, for example, by cron?
No, only those explicitly added to the kernel ring buffer.
syslog
dæmons can typically read from the kernel ring buffer on Linux, but that’s the only connection. I’m not aware of anything that writes to the buffer apart from the kernel (which doesn’t need a device to do so), and systemd (which will write to the kernel buffer if it can’t write to its journal or to syslog
).