Ejemplo n.º 1
0
 void free_proclist(proc_node *p)
{
    if ( p == NULL ) {
        return;
    } else {
        free_proclist( p->next );
    }
    free(p);
}
Ejemplo n.º 2
0
 int free_group()
{
    int i;

    printf("Freeing group...\n");
    for ( i=0; i<MAX_NUM_OF_GROUPS; i++ ) {
        free_proclist(bcastgroup[i].pproclist);
        free_buflist(bcastgroup[i].pbuflist); 
    }
}
Ejemplo n.º 3
0
int main() {

    /*DECLARATIONS*/
    struct command *L[100];
    char *cmdLine = calloc(100,sizeof(char)); //command line
    int *groupD;                              //keep track of directives
    char c;
    int numLists = 0;                         //number of lists created
    int listNum=0;                            //specific list to deal with
    int i;

    signal(SIGCHLD, bg_handler);    //allow children to die
    signal(SIGALRM, alarm_handler); //check efficiency

    L[numLists] = (struct command *)calloc(1, sizeof(struct command));
    initialize_list(L[numLists]);
    
    printf("My Shell > ");
    fflush(stdout);
    
    while(1) {
        c = getchar();
        
        switch(c) {
            case'\n':
                if (cmdLine[0] == '\0') {
                    printf("My Shell > ");
                }
                else { /*execute command line*/
                    
                    groupD = parse_cmdline(L[numLists], cmdLine);
                    if (groupD[0] == 0){
                        exec_cmdline(L[numLists]);
                    }
                    else {
                        /*directives*/
                        for (i=0; i<numLists+1; i++){
                            if (L[i]->group == groupD[1]){
                                directive(L[i], groupD[0]);
                            }
                        }
                    }
                    printf("My Shell > ");
                    
                    numLists++;
                    L[numLists] = (struct command *)calloc(1, sizeof(struct command));
                    initialize_list(L[numLists]);
                    reset_cmdline(cmdLine);
                }
            break;
            
            default:
                strncat(cmdLine, &c, 1);
                break;
        }
    }
    for (i=0; i<numLists+1; i++)
        free_proclist(L[i]);
    free_listofproclist(L);
    free(cmdLine);
return -1;
}