0

So I have a command that crashes the computer, and I wanted to see the output of dmesg to figure out the reason.

I saw that there is an -w option that allows dmesg to follow the process, but the problem is it does not exit so I cannot run the command following dmesg -w.

I tried

>     #!/bin/bash 
>     dmesg -w & 
>     echo image.raw | /sys/device/platform/inject_frame

but that still doesn't run in the background. Any advice on what can I do?

The kernel version I am using is 4.9.241

edit: Solution is provided by Harry , and is in the comment section. At the end I did (sudo journal -fk | sudo dd=log.txt) & to do what I desired, which is to capture the log of following actions to log.txt

To see what journalctl is different from dmesg, you can check it out here: https://www.reddit.com/r/redhat/comments/n3b278/can_someone_briefly_explain_the_major_differences/ What is the difference between dmesg and journalctl

ArMAaron
  • 3
  • 2
  • "but that still doesn't run in the background" – Why do you think so? What happens? What do you expect to happen? – Kamil Maciorowski Jul 27 '22 at 11:47
  • #!/bin/bash dmesg -w & echo image.raw | /sys/device/platform/inject_frame I would expect the script to continue and run the next line. but rightnow it stops at dmesg -w &. I am new to linux, and I thought & make the process run as a background process, please do correct me if there is anything wrong with my terminology – ArMAaron Jul 27 '22 at 15:58
  • I don't know what the purpose of `/sys/device/platform/inject_frame` is, but I really doubt `echo image.raw | /sys/device/platform/inject_frame` makes sense. The command tries to run `echo` and `/sys/device/platform/inject_frame`, but sysfs on `/sys` should be mounted with `noexec` and I don't expect any executable there. Depending on what `inject_frame` is, `echo image.raw > /sys/device/platform/inject_frame` or `cat image.raw > /sys/device/platform/inject_frame` may make sense. – Kamil Maciorowski Jul 27 '22 at 23:33
  • Yes I understand where you are coming from. that's just how the kernel modules works, I have access to the code and it takes the path and read instead. Anyways I am more looking to see how I can capture the output of the fram injection process. I am sure the operation works, I just need to capture informations about it – ArMAaron Jul 29 '22 at 11:14
  • My point is `echo image.raw | /sys/device/platform/inject_frame` tries to *execute* `/sys/device/platform/inject_frame`. – Kamil Maciorowski Jul 29 '22 at 11:32

1 Answers1

1

strace -p pid is more suitable to find out what happens while a pragram in running and it doesn't need root privileges. You can run it in the background like this:

nohup strace -p pid &

and follow the trace with tail -f nohup.out

Harry
  • 194
  • 4
  • thank you for your advice Harry, but I don't think there is a pid for what I am doing. Basically there is a kernal module that allows me to send an image to a image processor by echoing the image to a folder /sys/device/platform/inject_frame. and I am trying to debug the module since the vendor did not implement the module properly, the information is outputted to the kernel message buffer. – ArMAaron Jul 27 '22 at 15:54
  • I see, you were talking about a command in your question, not a kernel module. Depending on your syslog configuration the error message should also appear in the log. If you are using `systemd-journald` you can view it with `journalctl -k` – Harry Jul 27 '22 at 21:12
  • Yes, my apologies, I am not very accurate with my use of words. That is what I needed, was able to do what I wanted with journalctl. Thanks! – ArMAaron Jul 29 '22 at 11:33
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 31 '22 at 14:56