we have a script which runs below sysrq command to get memory info in syslog and then script copies the syslog.

echo -m > /proc/sysrq-trigger

From documentation I see that at the at kernel level "handle_sysrq" gets called which runs in the interrupt context but there are two ways sysrq is triggered right ?

  1. one is keys combination on keyboard. And
  2. another is by writing appropriate character to/proc/sysrq-trigger file.

Now we want to know if memory-info gets written to syslog/dmesg immediately before echo returns or it is memory-info is written after echo returns ?

1 Answer 1


I'm guessing your underlying question is how to make sure that the memory information has been logged by the time you copy the system log...

I haven't checked the code but I think it's all asynchronous. If you want to serialise operations you can do so by writing to /dev/kmsg; anything you write there ends up in the kernel buffer. So something like

echo m > /proc/sysrq-trigger
echo "whatever you want" > /dev/kmsg

should do the trick... You could even add a serial message to the message in /dev/kmsg so you're sure you're copying the right thing afterwards, or even wrap the memory dump with two messages.

  • Exactly that's the question I have :) Just to understand how will echoing to /dev/kmsg serializes that ?
    – ART
    Commented Sep 15, 2016 at 15:37
  • In the best case, everything's synchronous anyway, so the dump is logged by the time the echo m completes; but if it isn't, I think writing to /dev/kmsg is synchronous, so that will wait for the memory dump to complete, log the message from the second echo and when that completes, you know everything's been logged. (Lots of hand-waving here...) Commented Sep 15, 2016 at 15:44
  • Thank you Stephen, I get it. Let me wait for some more time if some has more information on this so that I understand it completely. However in documentation it is mentioned that handle_sysrq runs in interrupt context but I am not sure what is difference between keyboard interrupt(MagicSysRq key) and write to proc interface in echo m case.
    – ART
    Commented Sep 15, 2016 at 15:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .