{"id":9690,"date":"2018-06-12T10:31:38","date_gmt":"2018-06-12T08:31:38","guid":{"rendered":"http:\/\/www.b.shuttle.de\/hayek\/hayek\/jochen\/wp\/blog-en\/?p=9690"},"modified":"2018-06-12T10:31:38","modified_gmt":"2018-06-12T08:31:38","slug":"comparing-procfs-cmdline","status":"publish","type":"post","link":"https:\/\/wp.jochen.hayek.name\/blog-en\/2018\/06\/12\/comparing-procfs-cmdline\/","title":{"rendered":"comparing \/proc\/12345\/cmdline on Linux &#8212; &#8220;diff &#8211;text&#8221; vs &#8220;diff &#8211;brief &#8211;text&#8221; vs &#8220;cmp &#8211;silent&#8221;"},"content":{"rendered":"<ul>\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Procfs#Linux\">https:\/\/en.wikipedia.org\/wiki\/Procfs#Linux<\/a><\/li>\n<\/ul>\n<p>A <em>cmdline<\/em>\u00a0&#8220;file&#8221; contains NUL characters, so &#8220;<code>diff<\/code>&#8221; needs to be used with &#8220;<code>--text<\/code>&#8221; otherwise it will fail anyway.<\/p>\n<p>I chose process ID 12345 deliberately, it is just a placeholder.<\/p>\n<pre>$ cp \/proc\/12345\/cmdline $HOME\/cmdline\n\n$ ll \/proc\/12345\/cmdline ~\/cmdline\n-r--r--r-- 1 root root   <strong>0<\/strong> 2018-06-12 09:22:50 \/proc\/12345\/cmdline\n-r--r--r-- 1 user users 45 2018-06-12 09:48:19 \/homes\/user\/cmdline\n# \/proc\/12345\/cmdline is a file in the proc filesystem.\n# is the displayed size a bug or a feature?\n$ wc --bytes \/proc\/12345\/cmdline ~\/cmdline\n45 \/proc\/12345\/cmdline\n45 \/homes\/user\/cmdline\n90 total\n\n$ diff --text \/proc\/12345\/cmdline ~\/cmdline; echo $?\n0\n# as we expect\n\n$ diff --brief \/proc\/12345\/cmdline ~\/cmdline; echo $?\nFiles \/proc\/12345\/cmdline and \/homes\/user\/cmdline <strong>differ<\/strong>\n<strong>1<\/strong>\n# why are they now different?\n\n$ cmp --silent \/proc\/12345\/cmdline ~\/cmdline; echo $?\n<strong>1<\/strong>\n# why are they now different?\n<\/pre>\n<p>&#8220;<code>diff --brief --text<\/code>&#8221; and &#8220;<code>cmp --silent<\/code>&#8221; presumably take the file size into account.<\/p>\n<p>On Cygwin &#8220;<code>diff --brief --text<\/code>&#8221; behaves like &#8220;<code>diff --text<\/code>&#8220;.<\/p>\n<p>I was quite surprised to experience these differences. It took me quite a while to realise, where my surprising processing results came from.\t\t\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/en.wikipedia.org\/wiki\/Procfs#Linux A cmdline\u00a0&#8220;file&#8221; contains NUL characters, so &#8220;diff&#8221; needs to be used with &#8220;&#8211;text&#8221; 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&#8211;r&#8211;r&#8211; 1 root root 0 2018-06-12 09:22:50 \/proc\/12345\/cmdline -r&#8211;r&#8211;r&#8211; 1 user users 45 2018-06-12 09:48:19 \/homes\/user\/cmdline # [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_share_on_mastodon":"0"},"categories":[82,306],"tags":[1242],"class_list":["post-9690","post","type-post","status-publish","format-standard","hentry","category-cygwin","category-linux","tag-procfs"],"share_on_mastodon":{"url":"","error":""},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paO0kP-2wi","jetpack_likes_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/9690","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/comments?post=9690"}],"version-history":[{"count":0,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/9690\/revisions"}],"wp:attachment":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/media?parent=9690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/categories?post=9690"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/tags?post=9690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}