wp.jochen.hayek.name/blog-en

comparing /proc/12345/cmdline on Linux — “diff –text” vs “diff –brief –text” vs “cmp –silent”

A cmdline “file” contains NUL characters, so “diff” needs to be used with “--text” otherwise it will fail anyway.

I chose process ID 12345 deliberately, it is just a placeholder.

$ cp /proc/12345/cmdline $HOME/cmdline

$ ll /proc/12345/cmdline ~/cmdline
-r--r--r-- 1 root root   0 2018-06-12 09:22:50 /proc/12345/cmdline
-r--r--r-- 1 user users 45 2018-06-12 09:48:19 /homes/user/cmdline
# /proc/12345/cmdline is a file in the proc filesystem.
# is the displayed size a bug or a feature?
$ wc --bytes /proc/12345/cmdline ~/cmdline
45 /proc/12345/cmdline
45 /homes/user/cmdline
90 total

$ diff --text /proc/12345/cmdline ~/cmdline; echo $?
0
# as we expect

$ diff --brief /proc/12345/cmdline ~/cmdline; echo $?
Files /proc/12345/cmdline and /homes/user/cmdline differ
1
# why are they now different?

$ cmp --silent /proc/12345/cmdline ~/cmdline; echo $?
1
# why are they now different?

diff --brief --text” and “cmp --silent” presumably take the file size into account.

On Cygwin “diff --brief --text” behaves like “diff --text“.

I was quite surprised to experience these differences. It took me quite a while to realise, where my surprising processing results came from.

Exit mobile version