int Child(void *arg) { int pid; int state; int status = 0; USLOSS_Console("Child\n"); P1_DumpProcesses(); pid = P1_Fork("Grandchild", Grandchild, NULL, USLOSS_MIN_STACK, 2); if (pid < 0) { USLOSS_Console("Unable to fork child: %d\n", pid); status = 1; } else { /* * Grandchild runs at priority 2, which is higher than ours. Part A is * run-to-completion, the grandchild should already have quit before * we get here. */ // USLOSS_Console("Grandchild pid : %d,State=%d\n", pid,P1_GetState(pid)); state = P1_GetState(pid); if (state != 3) { // grandchild should have quit USLOSS_Console("Grandchild is in invalid state: %d\n", state); status = 1; } } return status; }
int P5_Startup(void *notused) { USLOSS_Console("P5_Startup\n"); P1_Fork("P6_Startup", P6_Startup, NULL, 4 * USLOSS_MIN_STACK, 1); USLOSS_Console("P5_Finished\n"); P1_DumpProcesses(); return 0; }
int P3_Startup(void *notused) { USLOSS_Console("P3_Startup\n"); P1_Fork("P5_Startup", P5_Startup, NULL, 4 * USLOSS_MIN_STACK, 5); int i; for (i = 0; i < 40; i++) { P1_Fork("P4_Startup", P4_Startup, NULL, 4 * USLOSS_MIN_STACK, 5); } P1_DumpProcesses(); int status = 2; int val = P1_Join(&status); printf("P1_Join return value: %d\n", val); P1_DumpProcesses(); P1_Fork("P8_Startup", P8_Startup, NULL, 4 * USLOSS_MIN_STACK, 3); USLOSS_Console("P3_Finished\n"); return 0; }
int P7_Startup(void *notused) { USLOSS_Console("P7_Startup\n"); P1_Quit(2); USLOSS_Console("P7_Finished\n"); P1_DumpProcesses(); return 0; }
int P2_Startup(void *notused) { int pid; int status = 0; USLOSS_Console("P2_Startup\n"); pid = P1_Fork("Child", Child, NULL, USLOSS_MIN_STACK, 3); // USLOSS_Console("Child pid : %d\n", pid); if (pid < 0) { USLOSS_Console("Unable to fork child: %d\n", pid); status = 1; } // USLOSS_Console("in p2Startup"); P1_DumpProcesses(); return status; }
void sysHandler(int type,void *arg) { if(arg == NULL){ USLOSS_Console("USLOSS_Sysargs is NULL!\n"); return; } USLOSS_Sysargs *sysArgs = (USLOSS_Sysargs *) arg; int retVal = 0; int retVal2 = 0; int sectSize = 0; int sectors = 0; int tracks = 0; interruptsOn(); switch (sysArgs->number) { case SYS_TERMREAD: retVal = P2_TermRead((int)sysArgs->arg3, (int)sysArgs->arg2, sysArgs->arg1); if(retVal >= 0){ sysArgs->arg4 = (void *)0; sysArgs->arg2 = (void *)retVal; }else{ sysArgs->arg4 = (void *)-1; } break; case SYS_TERMWRITE: retVal = P2_TermWrite((int)sysArgs->arg3,(int)sysArgs->arg2,(char *)sysArgs->arg1); if(retVal >= 0){ sysArgs->arg4 = (void *)0; sysArgs->arg2 = (void *)retVal; }else{ sysArgs->arg4 = (void *)-1; } break; case SYS_SPAWN: //Part 1 retVal = P2_Spawn(sysArgs->arg5, sysArgs->arg1, sysArgs->arg2, (int) sysArgs->arg3, (int) sysArgs->arg4); if (retVal == -3 || retVal == -2) { sysArgs->arg4 = (void *) -1; sysArgs->arg1 = (void *) -1; } else { sysArgs->arg1 = (void *) retVal; sysArgs->arg4 = (void *) 0; } break; case SYS_WAIT: //Part 1 retVal = P2_Wait(&retVal2); if(retVal == -1){ sysArgs->arg1 = (void *)-1; sysArgs->arg4 = (void *)-1; sysArgs->arg2 = (void *)-1; }else{ sysArgs->arg1 = (void *)retVal; sysArgs->arg2 = (void *)retVal2; sysArgs->arg4 = (void *)0; } break; case SYS_TERMINATE: //Part 1 P2_Terminate((int)sysArgs->arg1); break; case SYS_SLEEP: // Part 1 retVal = P2_Sleep((int)sysArgs->arg1); sysArgs->arg4 = (void *) retVal; break; case SYS_DISKREAD: retVal = P2_DiskRead((int)sysArgs->arg5,(int)sysArgs->arg3,(int) sysArgs->arg4,(int)sysArgs->arg2,(void *)sysArgs->arg1); if (retVal == -1) { sysArgs->arg1 = (void *)retVal; sysArgs->arg4 = (void *)-1; } else if (retVal == 0) { sysArgs->arg1 = (void *)0; sysArgs->arg4 = (void *)0; }else { sysArgs->arg1 = (void *)retVal; //output is the disk's status register sysArgs->arg4 = (void *)0; } break; case SYS_DISKWRITE: retVal = P2_DiskWrite((int)sysArgs->arg5,(int)sysArgs->arg3,(int) sysArgs->arg4,(int)sysArgs->arg2,(void *)sysArgs->arg1); if (retVal == -1) { sysArgs->arg1 = (void *)retVal; sysArgs->arg4 = (void *)-1; } else if (retVal == 0) { sysArgs->arg1 = (void *)0; sysArgs->arg4 = (void *)0; }else { sysArgs->arg1 = (void *)retVal; //output is the disk's status register sysArgs->arg4 = (void *)0; } break; case SYS_DISKSIZE: retVal = P2_DiskSize((int)sysArgs->arg1,§Size,§ors,&tracks); if (retVal == -1) { sysArgs->arg4 = (void *)-1; }else { sysArgs->arg4 = (void *)0; sysArgs->arg1 = (void *)sectSize; sysArgs->arg2 = (void *)sectors; sysArgs->arg3 = (void *)tracks; } break; case SYS_GETTIMEOFDAY: //Part 1 sysArgs->arg1 = (void *)USLOSS_Clock(); break; case SYS_CPUTIME: //Part 1 sysArgs->arg1 = (void *)P1_ReadTime(); break; case SYS_DUMPPROCESSES: //Part 1 P1_DumpProcesses(); break; case SYS_GETPID: //Part 1 sysArgs->arg1 = (void *) P1_GetPID(); break; case SYS_SEMCREATE: //Part 1 retVal = (int)sysArgs->arg1; if(retVal < 0){ sysArgs->arg4 = (void *)-1; }else{ sysArgs->arg4 = (void *)0; sysArgs->arg1 = (void *) semAdd(P1_SemCreate(retVal)); } break; case SYS_SEMP: // Part 1 if(validSem((int)sysArgs->arg1) == 0){ sysArgs->arg4 = (void *) -1; return; } retVal = P1_P(userSemList[(int)sysArgs->arg1].sem); if(retVal < 0){ sysArgs->arg4 = (void *) -1; } else{ sysArgs->arg4 = (void *) 0; } break; case SYS_SEMV: // Part 1 if(validSem((int)sysArgs->arg1) == 0){ sysArgs->arg4 = (void *) -1; return; } retVal = P1_V(userSemList[(int)sysArgs->arg1].sem); if(retVal < 0){ sysArgs->arg4 = (void *) -1; } else{ sysArgs->arg4 = (void *) 0; } break; case SYS_SEMFREE: // Part 1 if(validSem((int)sysArgs->arg1) == 0){ sysArgs->arg4 = (void *) -1; return; } retVal = semDelete((int)sysArgs->arg1); if(retVal < 0){ sysArgs->arg4 = (void *) -1; } else{ sysArgs->arg4 = (void *) 0; } break; case SYS_MBOXCREATE: //Part 1 retVal = P2_MboxCreate((int)sysArgs->arg1,(int)sysArgs->arg2); if(retVal == -2){ sysArgs->arg1 = (void *) -1; sysArgs->arg4 = (void *) -1; }else{ sysArgs->arg1 = (void *) retVal; sysArgs->arg4 = (void *) 0; } break; case SYS_MBOXRELEASE: // Part 1 retVal = P2_MboxRelease((int)sysArgs->arg1); if(retVal < 0){ sysArgs->arg4 = (void *) -1; }else{ sysArgs->arg4 = (void *) 0; } break; case SYS_MBOXSEND: // Part 1 retVal = P2_MboxSend((int)sysArgs->arg1,sysArgs->arg2,(int *)&sysArgs->arg3); if(retVal < 0){ sysArgs->arg4 = (void *) -1; }else{ sysArgs->arg4 = (void *) 0; } break; case SYS_MBOXRECEIVE: // Part 1 retVal = P2_MboxReceive((int)sysArgs->arg1,sysArgs->arg2,(int *)&sysArgs->arg3); if(retVal < 0){ sysArgs->arg4 = (void *) -1; }else{ sysArgs->arg4 = (void *) 0; sysArgs->arg2 = (void *) retVal; } break; case SYS_MBOXCONDSEND: // Part 1 retVal = P2_MboxCondSend((int)sysArgs->arg1,sysArgs->arg2,(int *)&sysArgs->arg3); if(retVal == -1){ sysArgs->arg4 = (void *) -1; }else if(retVal == -2){ sysArgs->arg4 = (void *) 1; } else{ sysArgs->arg4 = (void *) 0; } break; case SYS_MBOXCONDRECEIVE: // Part 1 retVal = P2_MboxCondReceive((int)sysArgs->arg1,sysArgs->arg2,(int *)&sysArgs->arg3); if(retVal == -1){ sysArgs->arg4 = (void *) -1; }else if(retVal == -2){ sysArgs->arg4 = (void *) 1; } else{ sysArgs->arg4 = (void *) 0; sysArgs->arg2 = (void *) retVal; } break; default: P1_Quit(1); } }