11541Srgrimessaute procfs lyonnais
21541Srgrimes
31541Srgrimesprocfs supports two levels of directory.  the filesystem root
41541Srgrimesdirectory contains a representation of the system process table.
51541Srgrimesthis consists of an entry for each active and zombie process, and
61541Srgrimesan additional entry "curproc" which always represents the process
71541Srgrimesmaking the lookup request.
81541Srgrimes
91541Srgrimeseach of the sub-directories contains several files.  these files
101541Srgrimesare used to control and interrogate processes.  the files implemented
111541Srgrimesare:
121541Srgrimes
131541Srgrimes	file	- xxx.  the exec'ed file.
141541Srgrimes
151541Srgrimes	status  - r/o.  returns process status.
161541Srgrimes
171541Srgrimes	ctl	- w/o.  sends a control message to the process.
181541Srgrimes			for example:
191541Srgrimes				echo hup > /proc/curproc/note
201541Srgrimes			will send a SIGHUP to the shell.
211541Srgrimes			whereas
221541Srgrimes				echo attach > /proc/1293/ctl
231541Srgrimes			would set up process 1293 for debugging.
241541Srgrimes			see below for more details.
251541Srgrimes
261541Srgrimes	mem	- r/w.  virtual memory image of the process.
271541Srgrimes			parts of the address space are readable
281541Srgrimes			only if they exist in the target process.
291541Srgrimes			a more reasonable alternative might be
301541Srgrimes			to return zero pages instead of an error.
311541Srgrimes			comments?
321541Srgrimes
331541Srgrimes	note	- w/o.  writing a string here sends the
341541Srgrimes			equivalent note to the process.
351541Srgrimes			[ not implemented. ]
361541Srgrimes
371541Srgrimes	notepg	- w/o.  the same as note, but sends to all
381541Srgrimes			members of the process group.
391541Srgrimes			[ not implemented. ]
401541Srgrimes
411541Srgrimes	regs	- r/w.	process register set.  this can be read
421541Srgrimes			or written any time even if the process
431541Srgrimes			is not stopped.  since the bsd kernel
441541Srgrimes			is single-processor, this implementation
451541Srgrimes			will get the "right" register values.
461541Srgrimes			a multi-proc kernel would need to do some
471541Srgrimes			synchronisation.
481541Srgrimes
491541Srgrimesthis then looks like:
501541Srgrimes
511541Srgrimes% ls -li /proc
521541Srgrimestotal 0
531541Srgrimes   9 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 0
541541Srgrimes  17 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 1
551541Srgrimes  89 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 10
561541Srgrimes  25 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 2
571541Srgrimes2065 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 257
581541Srgrimes2481 dr-xr-xr-x  2 jsp   staff  0 Sep 21 15:06 309
591541Srgrimes 265 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 32
601541Srgrimes3129 dr-xr-xr-x  2 jsp   staff  0 Sep 21 15:06 390
611541Srgrimes3209 dr-xr-xr-x  2 jsp   staff  0 Sep 21 15:06 400
621541Srgrimes3217 dr-xr-xr-x  2 jsp   staff  0 Sep 21 15:06 401
631541Srgrimes3273 dr-xr-xr-x  2 jsp   staff  0 Sep 21 15:06 408
641541Srgrimes 393 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 48
651541Srgrimes 409 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 50
661541Srgrimes 465 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 57
671541Srgrimes 481 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 59
681541Srgrimes 537 dr-xr-xr-x  2 root  kmem   0 Sep 21 15:06 66
691541Srgrimes 545 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 67
701541Srgrimes 657 dr-xr-xr-x  2 jsp   staff  0 Sep 21 15:06 81
711541Srgrimes 665 dr-xr-xr-x  2 jsp   staff  0 Sep 21 15:06 82
721541Srgrimes 673 dr-xr-xr-x  2 jsp   staff  0 Sep 21 15:06 83
731541Srgrimes 681 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 84
741541Srgrimes3273 dr-xr-xr-x  2 jsp   staff  0 Sep 21 15:06 curproc
751541Srgrimes% ls -li /proc/curproc
761541Srgrimestotal 408
771541Srgrimes3341 --w-------  1 jsp  staff       0 Sep 21 15:06 ctl
781541Srgrimes1554 -r-xr-xr-x  1 bin  bin     90112 Mar 29 04:52 file
791541Srgrimes3339 -rw-------  1 jsp  staff  118784 Sep 21 15:06 mem
801541Srgrimes3343 --w-------  1 jsp  staff       0 Sep 21 15:06 note
811541Srgrimes3344 --w-------  1 jsp  staff       0 Sep 21 15:06 notepg
821541Srgrimes3340 -rw-------  1 jsp  staff       0 Sep 21 15:06 regs
831541Srgrimes3342 -r--r--r--  1 jsp  staff       0 Sep 21 15:06 status
841541Srgrimes% df /proc/curproc /proc/curproc/file
851541SrgrimesFilesystem  512-blocks    Used   Avail Capacity  Mounted on
861541Srgrimesproc                 2       2       0   100%    /proc
871541Srgrimes/dev/wd0a        16186   13548    1018    93%    /
881541Srgrimes% cat /proc/curproc/status
891541Srgrimescat 446 439 400 81 12,0 ctty 748620684 270000 0 0 0 20000 nochan 11 20 20 20 0 21 117
901541Srgrimes
911541Srgrimes
921541Srgrimes
931541Srgrimesthe basic sequence of commands written to "ctl" would be
941541Srgrimes
951541Srgrimes	attach		- this stops the target process and
961541Srgrimes			  arranges for the sending process
971541Srgrimes			  to become the debug control process
981541Srgrimes	wait		- wait for the target process to come to
991541Srgrimes			  a steady state ready for debugging.
1001541Srgrimes	step		- single step, with no signal delivery.
1011541Srgrimes	run		- continue running, with no signal delivery,
1021541Srgrimes			  until next trap or breakpoint.
1031541Srgrimes	<signame>	- deliver signal <signame> and continue running.
1041541Srgrimes	detach		- continue execution of the target process
1051541Srgrimes			  and remove it from control by the debug process
1061541Srgrimes
1071541Srgrimesin a normal debugging environment, where the target is fork/exec'd by
1081541Srgrimesthe debugger, the debugger should fork and the child should stop itself
1091541Srgrimes(with a self-inflicted SIGSTOP).  the parent should do a "wait" then an
1101541Srgrimes"attach".  as before, the child will hit a breakpoint on the first
1111541Srgrimesinstruction in any newly exec'd image.
1121541Srgrimes
11350477Speter$FreeBSD$
114