/*-------------------------------------------------------------------------- * sehlltest - use shell command to test pipe machanism *-------------------------------------------------------------------------- */ void shelltest(void) { shell_pipid_test = pipcreate(); shell_piptr_test = &piptab[shell_pipid_test]; shellproducerid = create(shellproduce, 1024, 20, "shellproducer", 0); shellconsumerid = create(shellconsume, 1024, 20, "shellconsumer", 0); shellclockid = create(shellclock, 1024, 20, "shellclock", 0); pipconnect(shell_pipid_test, shellproducerid, shellconsumerid); resume(shellproducerid); resume(shellconsumerid); resume(shellclockid); pipdisconnect(shell_pipid_test); pipdelete(shell_pipid_test); }
shellcmd xsh_gen(int nargs, char *args[]) { pipid32 pip; pid32 rdpid,wrtpid; /* For argument '--help', emit help about the 'gen' command */ if (nargs == 2 && (strncmp(args[1], "--help", 7) == 0)) { printf("Use: %s\n\n", args[0]); printf("Description:\n"); printf("\tGenerates a word from wordlist and prints the count of words starting with vowel\n"); printf("Options:\n"); printf("\t | search\t it will print the number of words generated in 5 sec and count the number of words starting with vowels read from the pipe\n"); return 0; } if (nargs < 3) { fprintf(stderr, "%s: too few arguments\n", args[0]); fprintf(stderr, "Try '%s --help' for more information\n", args[0]); return 1; } else { if ((nargs == 3) && (strncmp(args[1], "|", 1) == 0) && (strncmp(args[2], "search", 6) == 0)) { //kprintf("correct usage \n\r"); if((pip = pipcreate()) == SYSERR) { kprintf("pipe creation unsuccessful \n\r"); return 0; } printsem = semcreate(1); rdpid = create(searchpipe, SHELL_CMDSTK, SHELL_CMDPRIO,"search", 2, pip, &printsem); wrtpid = getpid(); if(pipconnect(pip,wrtpid,rdpid) == SYSERR) { kprintf("pip connection failed \n\r"); return 0; } else { //kprintf("before resuming reader and writing\n\r"); resume(rdpid); writepip(pip); //resume(rdpid); kprintf("after writing\n\r"); } } } return 0; }
int main(int argc, char **argv) { pipid32 pip; pid32 reader; pid32 writer; if(SYSERR == (pip = pipcreate())) { return 0; } if(SYSERR == (reader = create(consume, 8196, 20, "read", 1, pip))) { return 0; } if(SYSERR == (writer = create(produce, 8196, 20, "write", 1, pip))) { return 0; } if((pipconnect(pip, writer, reader) == SYSERR)) { return 0; } resume(writer); resume(reader); while(1){ char command = getchar(); if(command == 10){ resume(reader); } if(command == 'q'){ break; } } kill(reader); kill(writer); pipdisconnect(pip); pipdelete(pip); return OK; }