SLIDE 43 Main Loop Process Manager
18041 PUBLIC int main(){ 18044 int result, s, proc_nr; 18045 struct mproc *rmp; 18046 sigset_t sigset; 18047 18048 pm_init(); /* initialize process manager tables */ 18049 18051 while (TRUE) { 18052 get_work(); /* wait for an PM system call */ ..... 18064 if ((unsigned) call_nr >= NCALLS) { 18065 result = ENOSYS; 18066 } else { 18067 result = (*call_vec[call_nr])(); 18068 } 18069 18070 /* Send the results back to the user to indicate completion. */ 18071 if (result != SUSPEND) setreply(who, result); /* Prepare reply message */ ..... 18075 /* Send out all pending reply messages, including the answer to 18076 * the call just made above. The processes must not be swapped out. 18077 */ 18078 for (proc_nr=0, rmp=mproc; proc_nr < NR_PROCS; proc_nr++, rmp++) { 18084 if ((rmp->mp_flags & (REPLY | ONSWAP | IN_USE | ZOMBIE)) == 18085 (REPLY | IN_USE)) { 18086 if ((s = send(proc_nr, &rmp->mp_reply)) != OK) { 18087 panic(__FILE__,"PM can’t reply to", proc_nr); 18088 } 18089 rmp->mp_flags &= ~REPLY; 18090 } 18091 } 18092 } 18093 return(OK); 18094 } .....
- 18099 PRIVATE void get_work(){
18101 /* Wait for the next message and extract useful information from it. */ 18102 if (receive(ANY, &m_in) != OK) panic(__FILE__,"PM receive error", NO_NUM); 18103 who = m_in.m_source; /* who sent the message */ 18104 call_nr = m_in.m_type; /* system call number */ 18105 18110 mp = &mproc[who < 0 ? PM_PROC_NR : who]; 18111 }
04 – 42 Memory Management/4.7 PM in MINIX