/* Abandon * All * Hope * Ye * Who * Enter * Here */ #include "smallsh.h" /*include file for example*/ #include #include #include /*program buffers, shared resources, and work pointers*/ static char inpbuf[MAXBUF], tokbuf[2*MAXBUF], *ptr = inpbuf, *tok = tokbuf; //Job list structure struct procnode { pid_t procid; int job; int status; char command[MAXBUF]; struct procnode *prevjob; struct procnode *nextjob; struct procnode *prevcom; struct procnode *nextcom; }; struct procnode *proclist; //signal handling struct sigaction sigact; void signal_handler(sig) int sig; { //if(sig == SIGINT) //TODO: Kill currently running foreground process in shell } void sigproc(void) { sigact.sa_handler = signal_handler; sigemptyset(&sigact.sa_mask); sigdelset(&sigact.sa_mask, SIGKILL); sigdelset(&sigact.sa_mask, SIGINT); sigact.sa_flags = 0; sigaction(SIGINT, &sigact, (struct sigaction *)NULL); } userin(p) /*print prompt and read a line*/ char *p; { int c, count; /*initialization for later routines*/ ptr = inpbuf; tok = tokbuf; /*display prompt*/ printf("%s ",p); for(count = 0;;) { if((c = getchar()) == EOF) return(EOF); if(count /*execute a command with optional wait*/ runcommand(cline,where, proclist) char **cline; int where; struct procnode *proclist; { int pid, exitstat, ret; if(strcasecmp(cline, "jobs")==0) //Have no idea if this is going to work { jobs(proclist); //No harm in trying } if((pid = fork()) <0) { perror("smallsh"); return(-1); } if(pid == 0) { /*child*/ execvp(*cline, cline); perror(*cline); exit(127); } /*code for parent*/ /*if background process print pid and exit*/ if(where == BACKGROUND) { printf("[Process id %d]\n", pid); return(0); } /*wait until process pid exists*/ while( (ret=wait(&exitstat)) != pid && ret != -1) ; return(ret == -1 ? -1 : exitstat); } #include "smallsh.h" jobs(proclist) struct procnode *proclist; { printf("HIDER"); } #include "smallsh.h" char *prompt = "Command>"; /*prompt*/ main() { sigproc(); while(userin(prompt) != EOF) procline(); }