int killTask(int taskId) { if (taskId != 0) // don't terminate shell { if (taskId < 0) // kill all tasks { int tid; for (tid = 1; tid < MAX_TASKS; tid++) { if (tcb[tid].name) exitTask(tid); } } else { // terminate individual task if (!tcb[taskId].name) return 1; exitTask(taskId); // kill individual task } } if (!superMode) SWAP; return 0; } // end killTask
int killTask(int taskId) { int tid; assert("killTask Error" && tcb[taskId].name); if (taskId != 0) // don't terminate shell { if (taskId < 0) // kill all tasks for (tid = 0; tid < MAX_TASKS; tid++) { if (tcb[tid].name) exitTask(tid); } else { free(tcb[taskId].argv); exitTask(taskId); // kill individual task } } if (!superMode) SWAP; return 0; } // end killTask
int killTask(int taskId) { if (taskId != 0) // don't terminate shell { if (taskId < 0) // kill all tasks { int tid; for (tid = 1; tid < MAX_TASKS; tid++) { if (tcb[tid].name) exitTask(tid); } } else { // terminate individual task if (!tcb[taskId].name) return 1; exitTask(taskId); // kill individual task // chack if parent task int newParent = -1; for (int i = 1; i < MAX_TASKS; i++) { if (tcb[i].parent == taskId) { //parent killed if (newParent == -1) { newParent = i; tcb[i].parent = 0; } else { tcb[i].parent = newParent; } } } } } if (!superMode) SWAP; return 0; } // end killTask