Exemple #1
0
void CProcessControl::RunWatchThread() {
	while (true)
	{
		Sleep(100);
		m_cSection.Lock();
		int nsum = m_pTransformData->m_pWatchData->size();
		for (int i = 0; i < nsum; i++) {

			PWATCH_PROCESS_INFORMATION pwatch = m_pTransformData->m_pWatchData->at(i);
			if (m_bIsWatchProcess) {
				if (!IsProcessExit(i) || pwatch->proinfo.dwProcessId == 0) {
					ADD_LOG_TIPS("can not find watching process, and recreate it");
					CLOSE_HANDLE(pwatch->proinfo.hProcess);
					CreateProcessList(i);
				}
			}
			else {
				if (pwatch->nstatus == RUN) {
					if (!IsProcessExit(i)) {
						ADD_CHECKLOG_TIPS("a abnormal process, changeing it status");
						pwatch->nstatus = EXIT;
						if (m_hWnd) ::PostMessage(m_hWnd, WM_UPDATEWATCHLIST, NULL, NULL);
					}
				}
			}
		}

		m_cSection.Unlock();
		if (WaitForSingleObject(m_hExitEvent, 1000) == WAIT_OBJECT_0)
		{
			break;
		}
	}
}
int main (int argc, const char * argv[]) {

    FILE   *fp;                                  /* Pointer to the file */
    int    quantum = 0;                /* Quantum value for Round Robin */
    int    parameters[NUMVAL];        /* Process parameters in the line */
    int    i;                    /* Number of parameters in the process */
    
    /* Check if the parameters in the main function are not empty */
    if (argc < NUMPARAMS){
        printf("Need a file with the process information\n\n");
        printf("Abnormal termination\n");
        return (EXIT_FAILURE);
    }
    else {
        
        /* Open the file and check that it exists */
        fp = fopen (argv[1],"r");       /* Open file for read operation */
        if (!fp)                            /* The file does not exists */
            ErrorMsg("'main'","Filename does not exist or is corrupted\n");
        
        else {
            
            /* The first number in the file is the quantum */
            quantum = GetInt(fp);
        
            if (quantum == EXIT_FAILURE)
                ErrorMsg("'main'","The quantum was not found");
            
            else {
                /* Read the process information until the end of file 
                is reached */
                while (!feof(fp)){
                    
                    /* For every four parameters create a new process */
                    for (i = 0; ((i < NUMVAL) && (!feof(fp))); i++) {
                        parameters[i] = GetInt(fp);
                    }
                    
                    /* Do we have only four parameters? */
                    if (i == NUMVAL) {
                        
                        /* Create a new process with its information */
                        CreateProcessList(parameters[0], parameters[1], parameters[2], parameters[3]);
                    }
                }
                
                /* Start by sorting the processes by arrival time */
                SortProcessList(ARRIVALTIME);
                
                /* Apply all the scheduling algorithms and print the results */
                 FirstComeFS();
                 NonPreemptive(CPUBURST);
                 NonPreemptive(PRIORITY);
                 Preemptive(CPUBURST);
                 Preemptive(PRIORITY);
                 RoundRobin(quantum);
                
            }
        }
        
    }
}