Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

AFAIK dmesg shows information about kernel and kernel modules, and /var/log/messages also shows information produced by kernel and modules.

So what's the difference? Does /var/log/messages output of dmesg?

More Info that may be helpful:
- There is a kernel ring buffer, which I think is the very and only place to store kernel log data.
- Article "Kernel logging: APIs and implementation" on IBM DeveloperWorks described APIs and the bird-view picture.

share|improve this question

3 Answers 3

up vote 10 down vote accepted

dmesg prints the contents of the ring buffer. This information is also sent in real time to syslogd or klogd, when they are running, and ends up in /var/log/messages; when dmesg is most useful is in capturing boot-time messages from before syslogd and/or klogd started, so that they will be properly logged.

share|improve this answer
1  
So /var/log/messages and dmesg will show the same logs (in different format) after syslogd and/or klogd started? –  xanpeng Apr 6 '12 at 4:56
2  
After klogd is running, dmesg will show only the most recent kernel messages (because the ring buffer is a fixed size and so can only hold so much), without timestamps or other information, while /var/log/messages will retain logs according to how logrotate is configured and include timestamping (which will be slightly inaccurate for initial boot messages because dmesg doesn't have them, so the time klogd started is used for all messages read from the kernel buffer). –  geekosaur Apr 6 '12 at 5:18
1  
@xanpeng dmesg only contains messages from the kernel, /var/log/messages usually contains logs from applications as well. –  Gilles Apr 6 '12 at 23:34

That depends on the operating system. For example on Solaris, dmesg is simply a shell script showing the last 200 lines of the /var/adm/messages.* files.

share|improve this answer

dmesg : dmesg is an (display od driver) message. It is used to examine or control the kernel ring buffer, hardware.

messages : It contains global system messages, including the messages that are logged during system startup. There are several things that are logged in /var/log/messages including mail, cron, daemon, kern, auth, etc.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.