home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol247 / examples.lbr / PS.DQC / ps.doc
Encoding:
Text File  |  1986-02-28  |  3.8 KB  |  70 lines

  1.  
  2.                     Documentation For PS.A86 
  3.  
  4.                     Process Spawning Example
  5.  
  6.  
  7. The program PS is an example of how to spawn processes and have 
  8. them run simultaneously under Concurrent CP/M.  This example 
  9. simulates a situation where there are four external "devices" 
  10. that are each monitored and controlled by independent processes.  
  11. These processes continually report their status to another 
  12. process, which displays the combined statuses on the screen.  In 
  13. this case, the only status that is being monitored is whether the 
  14. "device" is "on" or "off".
  15.  
  16. This example uses the P_CREATE function to create the sub-
  17. processes that will monitor the external devices.  The P_CREATE 
  18. function allows a programmer to create processes dynamically by 
  19. defining what the initial value of all of the registers are for 
  20. the new process, and then placing this process on the ready list.  
  21. Using this technique, this example will create 4 processes, each 
  22. with the same initial CS and DS values, but with different stack 
  23. areas.  This means that each of these processes will be executing 
  24. the exact same piece of code, but since each process will use a 
  25. separate stack area, no conflicts will arise.  When a program 
  26. uses the P_CREATE function, it must first set up a valid Process 
  27. Descriptor (PD) and a User Data Area (UDA) for each process that 
  28. it will create.  See the CCP/M Programmer's Guide for detailed 
  29. information about these two structures.
  30.  
  31. The main process is initiated by executing the program PS from 
  32. the console.  PS.CMD is created by running PS.A86 through RASM86 
  33. and LINK86.  No special parameters are necessary for either of 
  34. these utilities when assembling PS.  The main process first 
  35. initializes the PD and UDA for each of the sub-processes.  The 
  36. UDA's have been initialized so that each has the same code and 
  37. data segments.  All of the other registers except BX are 
  38. initialized to zero.  Register BX is initialized to the number of 
  39. the sub-process.  Since there are four sub-processes, this value 
  40. will range from 0 to 3.  The Process Descriptors are all linked 
  41. by the Link field of the PD, so only one P_CREATE call is needed.  
  42. Once the P_CREATE call is made, the initial (main) process prints 
  43. the signon message, and then loops printing the status of each of 
  44. the "devices".  
  45.  
  46. Since the four sub-processes simulate the "on/off" status of some 
  47. external device, they all need to be able to communicate this 
  48. information to the main process.  Because all five processes 
  49. share the same data area, it is easy to pass information from one 
  50. process to another.  This is done by setting up a "status line" 
  51. area in the data segment.  This status line is continually being 
  52. printed by the main process, while each of the sub-processes 
  53. toggle one of the bytes from a "0" to indicate the device is off, 
  54. to a "1" to indicate the device is on.  The status of the device 
  55. (whether it is on or off) is continually toggled after a random 
  56. amount of time has passed.  The sub-processes use the initial 
  57. value in BX as an index into the status line to compute which 
  58. byte to update.
  59.  
  60. Another shared value in the data segment is an abort flag.  The 
  61. sub-processes monitor this byte.  When its value becomes 1, each 
  62. of the sub-processes will abort itself.  The main process sets 
  63. this value to one when a character is typed at the keyboard.  
  64. This is one way for a main process to terminate its sub-
  65. processes.  Note that simply pressing control-c at the console 
  66. will not suffice.  This will only terminate the main process, 
  67. leaving all of the sub-processes running in background until 
  68. either the ABORT or STOP command is used on each of them, or the 
  69. system is re-booted.
  70.