Example #1
0
// This is the final process called by main()
// It is responsible for:
//   * Receiving and executing commands from the java GUI
//   * Killing off all processes when exiting the application
void uicommand_process(void) {
    int i;
    int current_person_id = 0;
    char message[SI_UI_MAX_MESSAGE_SIZE];
    int pid;
    while(1) {
        // Read a message from the GUI
        si_ui_receive(message);
        if(!strcmp(message, "new")) {
            // TODO:
            // * Check that we don't create too many persons
            // * fork and create a new person process (and
            //   record the new pid in person_pid[])
            if (current_person_id + 1 < MAX_N_PERSONS) {
                pid = fork();
                current_person_id++;
                if (!pid) {
                    person_process(current_person_id);
                } else {
                    person_pid[current_person_id] = pid;
                }
            }
        } else if (!strncmp(message, "test", 4)) {

            switch ((int) (message[5] - '0')) {
            case 0:
                for (i=0; i<MAX_N_PERSONS; i++) {
                    if (current_person_id + 1 < MAX_N_PERSONS) {
                        pid = fork();
                        current_person_id++;
                        if (!pid) {
                            person_process(current_person_id);
                        } else {
                            person_pid[current_person_id] = pid;
                        }
                    }
                }
            }
        } else if(!strcmp(message, "exit")) {
            // The code below sends the SIGINT signal to
            // all processes involved in this application
            // except for the uicommand process itself
            // (which is exited by calling exit())
            kill(uidraw_pid, SIGINT);
            kill(lift_pid, SIGINT);
            kill(liftmove_pid, SIGINT);
            kill(guard_pid, SIGINT);
            for(i=0; i < MAX_N_PERSONS; i++) {
                if(person_pid[i] > 0) {
                    kill(person_pid[i], SIGINT);
                }
            }
            exit(0);
        }
    }
}
Example #2
0
int main(int argc, char **argv)
{
	message_init();
	
	lift_pid = fork();
	if(!lift_pid) {
		lift_process();
	}
	liftmove_pid = fork();
	if(!liftmove_pid){
		liftmove_process();
	}
	
	int current_person_id = 0;
	int j;
	for(j = 0; j < MAX_N_PERSONS; j++){
	  pid_t tmp_pid = fork();
	  if (tmp_pid == 0){
	    person_process(current_person_id);
	  } else{
	    person_pid[current_person_id] = tmp_pid;
	    current_person_id ++;
	  }
	}
	
	result_process();
	
	return 0;
}
Example #3
0
int main(int argc, char **argv) {
    int i;
    int current_person_id = 0;
    int pid;

    printf("Length of time_msg: %lld \n", sizeof(struct long_time_msg));
    message_init();
    si_ui_init(); // Initialize user interface. (Must be done here!)

    lift_pid = fork();
    if(!lift_pid) {
        lift_process();
    }
    uidraw_pid = fork();
    if(!uidraw_pid) {
        uidraw_process();
    }
    liftmove_pid = fork();
    if(!liftmove_pid) {
        liftmove_process();
    }

    guard_pid = fork();
    if(!guard_pid) {
        file_guard_process();
    }
    for (i=0; i<MAX_N_PERSONS; i++) {
        if (current_person_id < MAX_N_PERSONS) {
            pid = fork();
            if (!pid) {
                person_process(current_person_id);
            } else {
                person_pid[current_person_id++] = pid;
            }
        }
    }

    uicommand_process();

    return 0;
}