linux kernel - Incorrect file sizes in /procfs and Incorrect values in /proc/[pid]/stat -


the ls -l /proc command gives file size 0 files in /proc dir.

ls -l /proc/

dr-xr-xr-x 7 root root 0 dec 31 17:23 1

dr-xr-xr-x 7 root root 0 dec 31 17:24 10

dr-xr-xr-x 7 root root 0 dec 31 17:24 103

dr-xr-xr-x 7 root root 0 dec 31 17:24 105

  file size calculated in kernel?   , /proc/[pid]/stat has junk characters. because of processes not listed in ps command output. /proc/[pid]/status has valid information. 

cat /proc/1/stat

'Ð3 0 0 0 20 0 0 0 0 0 0 9688 403/ 01607 1 269 7 41 20 0 1 0 12 Í7/60 109 2ÿp9 65536 403/ Øß9¾ ØÝ;¶ cù7² 0 0 0 @

cat /proc/2/stat

2 (kthreadd) s 0 0 0 0 -1 00.4 0 0 0 0 0 0 0 0 20 0 1 0 12 0 0 2ÿp9 0 0 0 0 0 0 0 2ÿp9 0 0 0 0 0 0 0 0 0 0 0 0 0 0

cat /proc/112/stat

112 (telnetd) s 1 112 112 0 -1 Ô,",0 124 0 1 0 3 27 0 0 20 0 1 0 942 7136 104 2ÿp9 65536 @6136 u?9¶ t?=¶ jý7¶ 0 0 /(25 d4288 0 0 0 20 0 0 0 0 0 0 @3840 @6136 c6608 #

where processes stat files written values in kernel source code?  

the flags field has junk chars. because of this, cat output has junk chars. using 3.4 kernel. flag field filled in stat file?.

hexdump -vc /proc/1/stat

00000000 31 20 28 69 6e 69 74 29 20 53 20 30 20 31 20 31 |1 (init) s 0 1 1|

00000010 20 30 20 2d 31 20 d4 2c 22 2c 30 20 38 38 20 31 | 0 -1 .,",0 88 1|

00000020 38 39 34 20 31 37 20 37 20 30 20 32 37 31 20 37 |894 17 7 0 271 7|

00000030 20 34 32 20 32 30 20 30 20 31 20 30 20 31 32 20 | 42 20 0 1 0 12 |

00000040 cd 37 2f 36 30 20 31 30 39 20 32 ff 70 03 39 20 |.7/60 109 2.p.9 |

00000050 36 35 35 33 36 20 85 34 30 33 2f 20 64 dc 91 3d |65536 .403/ d..=|

00000060 ba 20 64 db 90 3e bc 20 43 18 f9 37 b2 20 30 20 |. d..>. c..7. 0 |

00000070 30 20 30 20 40 0d 27 d0 33 20 30 20 30 20 30 20 |0 0 @.'.3 0 0 0 |

00000080 32 30 20 30 20 30 20 30 20 30 20 30 20 30 20 84 |20 0 0 0 0 0 0 .|

00000090 39 36 38 38 20 85 34 30 33 2f 20 86 30 31 36 30 |9688 .403/ .0160|

000000a0 0a |.|

000000a1


Comments