ReadingProcCmdLine

17th October 2016 at 11:30am
Bash CodeSnippets

If you want to read the arguments to a command from /proc/cmdline, you need to make sure you are delimiting each argument with a NULL character instead of space:

while read -r arg ; do echo "$arg" ; done < <(tr '\000' '\n' < /proc/$(pgrep abrt-watch-log)/cmdline)

[root@host ~]# ps -ef | grep abrt
root       622     1  0 Oct11 ?        00:00:00 /usr/sbin/abrtd -d -s
root       623     1  0 Oct11 ?        00:00:13 /usr/bin/abrt-watch-log -F BUG: WARNING: at WARNING: CPU: INFO: possible recursive locking detected ernel BUG at list_del corruption list_add corruption do_IRQ: stack overflow: ear stack overflow (cur: eneral protection fault nable to handle kernel ouble fault: RTNL: assertion failed eek! page_mapcount(page) went negative! adness at NETDEV WATCHDOG ysctl table check failed : nobody cared IRQ handler type mismatch Machine Check Exception: Machine check events logged divide error: bounds: coprocessor segment overrun: invalid TSS: segment not present: invalid opcode: alignment check: stack segment: fpu exception: simd exception: iret exception: /var/log/messages -- /usr/bin/abrt-dump-oops -xtD
root     20017 18950  0 11:19 pts/0    00:00:00 grep --color=auto abrt
[root@host ~]# while read -r arg ; do echo "$arg" ; done < <(tr '\000' '\n' < /proc/$(pgrep abrt-watch-log)/cmdline)
/usr/bin/abrt-watch-log
-F
BUG:
WARNING: at
WARNING: CPU:
INFO: possible recursive locking detected
ernel BUG at
list_del corruption
list_add corruption
do_IRQ: stack overflow:
ear stack overflow (cur:
eneral protection fault
nable to handle kernel
ouble fault:
RTNL: assertion failed
eek! page_mapcount(page) went negative!
adness at
NETDEV WATCHDOG
ysctl table check failed
: nobody cared
IRQ handler type mismatch
Machine Check Exception:
Machine check events logged
divide error:
bounds:
coprocessor segment overrun:
invalid TSS:
segment not present:
invalid opcode:
alignment check:
stack segment:
fpu exception:
simd exception:
iret exception:
/var/log/messages
--
/usr/bin/abrt-dump-oops
-xtD