186d7f5d3SJohn Marinosaute procfs lyonnais 286d7f5d3SJohn Marino 386d7f5d3SJohn Marinoprocfs supports two levels of directory. the filesystem root 486d7f5d3SJohn Marinodirectory contains a representation of the system process table. 586d7f5d3SJohn Marinothis consists of an entry for each active and zombie process, and 686d7f5d3SJohn Marinoan additional entry "curproc" which always represents the process 786d7f5d3SJohn Marinomaking the lookup request. 886d7f5d3SJohn Marino 986d7f5d3SJohn Marinoeach of the sub-directories contains several files. these files 1086d7f5d3SJohn Marinoare used to control and interrogate processes. the files implemented 1186d7f5d3SJohn Marinoare: 1286d7f5d3SJohn Marino 1386d7f5d3SJohn Marino file - xxx. the exec'ed file. 1486d7f5d3SJohn Marino 1586d7f5d3SJohn Marino status - r/o. returns process status. 1686d7f5d3SJohn Marino 1786d7f5d3SJohn Marino ctl - w/o. sends a control message to the process. 1886d7f5d3SJohn Marino for example: 1986d7f5d3SJohn Marino echo hup > /proc/curproc/note 2086d7f5d3SJohn Marino will send a SIGHUP to the shell. 2186d7f5d3SJohn Marino whereas 2286d7f5d3SJohn Marino echo attach > /proc/1293/ctl 2386d7f5d3SJohn Marino would set up process 1293 for debugging. 2486d7f5d3SJohn Marino see below for more details. 2586d7f5d3SJohn Marino 2686d7f5d3SJohn Marino mem - r/w. virtual memory image of the process. 2786d7f5d3SJohn Marino parts of the address space are readable 2886d7f5d3SJohn Marino only if they exist in the target process. 2986d7f5d3SJohn Marino a more reasonable alternative might be 3086d7f5d3SJohn Marino to return zero pages instead of an error. 3186d7f5d3SJohn Marino comments? 3286d7f5d3SJohn Marino 3386d7f5d3SJohn Marino note - w/o. writing a string here sends the 3486d7f5d3SJohn Marino equivalent note to the process. 3586d7f5d3SJohn Marino [ not implemented. ] 3686d7f5d3SJohn Marino 3786d7f5d3SJohn Marino notepg - w/o. the same as note, but sends to all 3886d7f5d3SJohn Marino members of the process group. 3986d7f5d3SJohn Marino [ not implemented. ] 4086d7f5d3SJohn Marino 4186d7f5d3SJohn Marino regs - r/w. process register set. this can be read 4286d7f5d3SJohn Marino or written any time even if the process 4386d7f5d3SJohn Marino is not stopped. since the bsd kernel 4486d7f5d3SJohn Marino is single-processor, this implementation 4586d7f5d3SJohn Marino will get the "right" register values. 4686d7f5d3SJohn Marino a multi-proc kernel would need to do some 4786d7f5d3SJohn Marino synchronisation. 4886d7f5d3SJohn Marino 4986d7f5d3SJohn Marinothis then looks like: 5086d7f5d3SJohn Marino 5186d7f5d3SJohn Marino% ls -li /proc 5286d7f5d3SJohn Marinototal 0 5386d7f5d3SJohn Marino 9 dr-xr-xr-x 2 root wheel 0 Sep 21 15:06 0 5486d7f5d3SJohn Marino 17 dr-xr-xr-x 2 root wheel 0 Sep 21 15:06 1 5586d7f5d3SJohn Marino 89 dr-xr-xr-x 2 root wheel 0 Sep 21 15:06 10 5686d7f5d3SJohn Marino 25 dr-xr-xr-x 2 root wheel 0 Sep 21 15:06 2 5786d7f5d3SJohn Marino2065 dr-xr-xr-x 2 root wheel 0 Sep 21 15:06 257 5886d7f5d3SJohn Marino2481 dr-xr-xr-x 2 jsp staff 0 Sep 21 15:06 309 5986d7f5d3SJohn Marino 265 dr-xr-xr-x 2 root wheel 0 Sep 21 15:06 32 6086d7f5d3SJohn Marino3129 dr-xr-xr-x 2 jsp staff 0 Sep 21 15:06 390 6186d7f5d3SJohn Marino3209 dr-xr-xr-x 2 jsp staff 0 Sep 21 15:06 400 6286d7f5d3SJohn Marino3217 dr-xr-xr-x 2 jsp staff 0 Sep 21 15:06 401 6386d7f5d3SJohn Marino3273 dr-xr-xr-x 2 jsp staff 0 Sep 21 15:06 408 6486d7f5d3SJohn Marino 393 dr-xr-xr-x 2 root wheel 0 Sep 21 15:06 48 6586d7f5d3SJohn Marino 409 dr-xr-xr-x 2 root wheel 0 Sep 21 15:06 50 6686d7f5d3SJohn Marino 465 dr-xr-xr-x 2 root wheel 0 Sep 21 15:06 57 6786d7f5d3SJohn Marino 481 dr-xr-xr-x 2 root wheel 0 Sep 21 15:06 59 6886d7f5d3SJohn Marino 537 dr-xr-xr-x 2 root kmem 0 Sep 21 15:06 66 6986d7f5d3SJohn Marino 545 dr-xr-xr-x 2 root wheel 0 Sep 21 15:06 67 7086d7f5d3SJohn Marino 657 dr-xr-xr-x 2 jsp staff 0 Sep 21 15:06 81 7186d7f5d3SJohn Marino 665 dr-xr-xr-x 2 jsp staff 0 Sep 21 15:06 82 7286d7f5d3SJohn Marino 673 dr-xr-xr-x 2 jsp staff 0 Sep 21 15:06 83 7386d7f5d3SJohn Marino 681 dr-xr-xr-x 2 root wheel 0 Sep 21 15:06 84 7486d7f5d3SJohn Marino3273 dr-xr-xr-x 2 jsp staff 0 Sep 21 15:06 curproc 7586d7f5d3SJohn Marino% ls -li /proc/curproc 7686d7f5d3SJohn Marinototal 408 7786d7f5d3SJohn Marino3341 --w------- 1 jsp staff 0 Sep 21 15:06 ctl 7886d7f5d3SJohn Marino1554 -r-xr-xr-x 1 bin bin 90112 Mar 29 04:52 file 7986d7f5d3SJohn Marino3339 -rw------- 1 jsp staff 118784 Sep 21 15:06 mem 8086d7f5d3SJohn Marino3343 --w------- 1 jsp staff 0 Sep 21 15:06 note 8186d7f5d3SJohn Marino3344 --w------- 1 jsp staff 0 Sep 21 15:06 notepg 8286d7f5d3SJohn Marino3340 -rw------- 1 jsp staff 0 Sep 21 15:06 regs 8386d7f5d3SJohn Marino3342 -r--r--r-- 1 jsp staff 0 Sep 21 15:06 status 8486d7f5d3SJohn Marino% df /proc/curproc /proc/curproc/file 8586d7f5d3SJohn MarinoFilesystem 512-blocks Used Avail Capacity Mounted on 8686d7f5d3SJohn Marinoproc 4 4 0 100% /proc 8786d7f5d3SJohn Marino/dev/ad0s1a 254063 102444 131294 44% / 8886d7f5d3SJohn Marino% cat /proc/curproc/status 8986d7f5d3SJohn Marinocat 446 439 400 81 12,0 ctty 748620684 270000 0 0 0 20000 nochan 11 20 20 20 0 21 117 9086d7f5d3SJohn Marino 9186d7f5d3SJohn Marino 9286d7f5d3SJohn Marino 9386d7f5d3SJohn Marinothe basic sequence of commands written to "ctl" would be 9486d7f5d3SJohn Marino 9586d7f5d3SJohn Marino attach - this stops the target process and 9686d7f5d3SJohn Marino arranges for the sending process 9786d7f5d3SJohn Marino to become the debug control process 9886d7f5d3SJohn Marino wait - wait for the target process to come to 9986d7f5d3SJohn Marino a steady state ready for debugging. 10086d7f5d3SJohn Marino step - single step, with no signal delivery. 10186d7f5d3SJohn Marino run - continue running, with no signal delivery, 10286d7f5d3SJohn Marino until next trap or breakpoint. 10386d7f5d3SJohn Marino <signame> - deliver signal <signame> and continue running. 10486d7f5d3SJohn Marino detach - continue execution of the target process 10586d7f5d3SJohn Marino and remove it from control by the debug process 10686d7f5d3SJohn Marino 10786d7f5d3SJohn Marinoin a normal debugging environment, where the target is fork/exec'd by 10886d7f5d3SJohn Marinothe debugger, the debugger should fork and the child should stop itself 10986d7f5d3SJohn Marino(with a self-inflicted SIGSTOP). the parent should do a "wait" then an 11086d7f5d3SJohn Marino"attach". as before, the child will hit a breakpoint on the first 11186d7f5d3SJohn Marinoinstruction in any newly exec'd image. 11286d7f5d3SJohn Marino 11386d7f5d3SJohn Marino$FreeBSD: src/sys/miscfs/procfs/README,v 1.4 1999/08/28 00:46:53 peter Exp $ 11486d7f5d3SJohn Marino$DragonFly: src/sys/vfs/procfs/README,v 1.3 2005/02/26 12:00:55 swildner Exp $ 115