int main(int argc, char *argv[]) { int opt; optflags = 0; outflags = OF_PID|OF_TTY|OF_TIME|OF_CMD; while((opt = getopt(argc, argv, "AeaNrp:t:U:u:lf")) != -1) { switch(opt) { case 'A': case 'e': /* Show everything */ optflags |= F_e; break; case 'a': /* All except session leaders and not associated with tty. We only do not assoc */ optflags |= F_a; break; case 'N': /* Invert match */ optflags |= F_N; break; /* BSDism : keep if doesn't clash */ case 'r': /* Only running processes */ optflags |= F_r; break; case 'p': /* Must match this pid */ optflags |= F_p; add_pidmatch(optarg); break; case 't': optflags |= F_t; add_ttymatch(optarg); break; case 'U': case 'u': /* -u deviates from the standard */ optflags |= F_u; add_uidmatch(optarg); break; case 'l': outflags |= OF_F|OF_S|OF_UID|OF_PID|OF_PPID| OF_C|OF_PRI|OF_NI|OF_ADDR|OF_SZ| OF_WCHAN|OF_TTY|OF_TIME|OF_CMD; break; case 'f': outflags |= OF_UID|OF_PID|OF_PPID|OF_C| OF_STIME|OF_TTY|OF_TIME|OF_CMD; break; default: usage(); } } if (optind != argc) usage(); return do_ps(); }
/****************** syscall handler in C ***************************/ int kcinth(){ u16 segment, offset; int a,b,c,d, r; segment = running->uss; offset = running->usp; /** get syscall parameters from ustack **/ a = get_word(segment, offset + 2*PA); b = get_word(segment, offset + 2*PB); c = get_word(segment, offset + 2*PC); d = get_word(segment, offset + 2*PD); //printf("proc%d syscall a=%d b=%d c=%d d=%d\n", running->pid, a,b,c,d); switch(a){ case 0 : r = running->pid; break; case 1 : r = do_ps(); break; case 2 : r = chname(b); break; case 3 : r = kmode(); break; case 4 : r = tswitch(); break; case 5 : r = do_wait(b); break; case 6 : r = do_exit(b); break; case 90: r = getc(); break; case 91: r = putc(b); break; case 99: do_exit(b); break; default: printf("invalid syscall # : %d\n", a); } put_word(r, segment, offset + 2*AX); }
int body(void) { char c, str[64]; printf("proc %d resumes to body()\n\r", running->pid); showLists(); while(1) { printf("\rproc %d running : enter a key [s|f|z|a|w|q|u|p|l]: ", running->pid); c = getc(); printf("%c\n\r", c); switch(c) { case 's': tswitch(); break; case 'q': do_exit(); break; case 'f': kfork("/bin/u1"); break; case 'z': do_sleep(); break; case 'a': do_wake(); break; case 'w': do_wait(); break; case 'u': goUmode(); break; case 'p': do_ps(); break; case 'l': showLists();break; default: break; } } }
int kcinth() { u16 segment, offset; int a,b,c,d, r; segment = running->uss; offset = running->usp; a = get_word(segment, offset + 2*PA); b = get_word(segment, offset + 2*PB); c = get_word(segment, offset + 2*PC); d = get_word(segment, offset + 2*PD); /*printf("interupthandler a = %d\n", a); printf("b = %d\n", b); printf("string: %s\n", c); printf("n = %d\n", d);*/ switch(a){ case 0 : r = running->pid; break; case 1 : r = do_ps(); break; case 2 : r = kchname(b); break; case 3 : r = kmode(); break; case 4 : r = tswitch(); break; case 5 : r = do_wait(b); break; case 6 : r = do_exit(b); break; case 7 : r = fork(); break; case 8 : r = exec(b); break; /****** these are YOUR pipe functions ************/ case 30 : r = kpipe(b); break; case 31 : r = read_pipe(b,c,d); break; case 32 : r = write_pipe(b,c,d); break; case 33 : r = close_pipe(b); break; case 34 : r = pfd(); break; /**************** end of pipe functions ***********/ case 90: r = getc(); break; case 91: color=running->pid+11; r = putc(b); break; case 99: do_exit(b); break; default: printf("invalid syscall # : %d\n", a); } //printf("interupthandler r = %d\n", r); //getc(); put_word(r, segment, offset + 2*AX); }
int main(int argc, char ** argv) { char c; while((c = getopt(argc, argv, "t")) >= 0) { switch(c) { case 't': display_threads = true; break; default: usage(argv[0]); } } do_ps(); return 0; }
int kcinth() { u16 segment, offset; int a,b,c,d, r; segment = running->uss; offset = running->usp; a = get_word(segment, offset + 2*PA); b = get_word(segment, offset + 2*PB); c = get_word(segment, offset + 2*PC); d = get_word(segment, offset + 2*PD); switch(a){ case 0 : r = running->pid; break; case 1 : r = do_ps(); break; case 2 : r = chname(b); break; case 3 : r = kmode(); break; case 4 : r = tswitch(); break; case 5 : r = do_wait(b); break; case 6 : r = do_exit(b); break; case 7 : r = fork(); break; case 8 : r = exec(b); break; case 9 : r = vfork(); break; case 30 : r = kpipe(b); break; case 31 : r = read_pipe(b,c,d); break; case 32 : r = write_pipe(b,c,d); break; case 33 : r = close_pipe(b); break; case 34 : r = pfd(); break; case 90: r = getc(); break; case 91: color=running->pid+11; r = putc(b); break; case 99: do_exit(b); break; default: printf("invalid syscall # : %d\n", a); } put_word(r, segment, offset + 2*AX); }
int main(int argc, char *argv[]) { int i; flags = 0; for (i = 1; i < argc; ++i) { char *p = argv[i]; if (*p == '-') ++p; while (*p) switch (*p++) { case 'a': flags |= F_a; break; case 'h': flags |= F_h; break; case 'r': flags |= F_r; break; case 'n': flags |= F_n; break; default: fprintf(stderr, "usage: ps [-][ahrn]\n"); return 1; } } return do_ps(); }
int kcinth() { ushort seg, off, r; int x, y, z, w; seg = running->uss; off = running->usp; x = get_word(seg, off + 2*13); y = get_word(seg, off + 2*14); z = get_word(seg, off + 2*15); w = get_word(seg, off + 2*16); switch(x){ case 0 : r = running->pid; break; case 1 : r = do_ps(); break; case 2 : r = chname(y); break; case 3 : r = kmode(); break; case 4 : r = tswitch(); break; case 5 : r = do_wait(y); break; case 6 : r = do_exit(y); break; case 7 : r = ufork(); break; case 8 : r = exec(y); break; case 9 : r = chcolor(y); break; case 10: r = putc(y); break; case 11: mysleep(y); break; case 99 : do_exit(y); break; default: printf("invalid syscall # : %d\n", x); break; } put_word(r, seg, off + 2*8); }
int body() { char c; printf("proc %d resumes to body()\n", running->pid); while(1) { printf("-----------------------------------------\n"); //print freeList; printf("Free List:\n"); printQueue(freeList); // print readyQueue; printf("Ready Queue:\n"); printQueue(readyQueue); // print sleepList; printf("Sleep List:\n"); printSleepQueue(sleepList); printf("-----------------------------------------\n"); printf("proc %d[%d] running: parent=%d\n", running->pid, running->priority, running->ppid); printf("type a char [s|f|q| p|z|a| w ] : "); c = getc(); printf("%c\n", c); switch(c){ case 's' : do_tswitch(); break; case 'f' : do_kfork(); break; case 'q' : do_exit(); break; case 'p' : do_ps(); break; case 'z' : do_sleep(); break; case 'a' : do_wakeup(); break; case 'w' : do_wait(); break; } } }
int kbhandler() { int scode, value, c; KBD *kp = &kb; /* Fetch the character from the keyboard hardware and acknowledge it. */ scode = in_byte(KEYBD); /* get the scan code of the key struck */ value = in_byte(PORT_B); /* strobe the keyboard to ack the char */ out_byte(PORT_B, value | KBIT); /* first, strobe the bit high */ out_byte(PORT_B, value); /* then strobe it low */ // printf("scode=%x\n", scode); if (scode == 0xE0) // ESC key esc++; // inc esc count by 1 if (esc && esc < 2) // only the first ESC key, wait for next code goto out; if (esc == 2){ // two 0xE0 means escape sequence key release if (scode == 0xE0) // this is the 2nd E0 itself, real code will come next goto out; // with esc==2, this must be the actual scan code, so handle it scode &= 0x7F; // leading bit off if (scode == 0x38){ // Right Alt alt = 0; goto out; } if (scode == 0x1D){ // Right Control release control = 0; goto out; } if (scode == 0x48){ // up arrow arrowKey = 0x0B; printf("UP arrow key\n"); } esc = 0; goto out; } if (scode & 0x80){ // key release: ONLY catch release of shift, control,alt scode &= 0x7F; // mask out bit 7 if (scode == LSHIFT || scode == RSHIFT) shifted = 0; // released the shift key if (scode == CONTROL) control = 0; // released the Control key if (scode == ALT) alt = 0; // released the ALT key goto out; } // from here on, must be key press if (scode == 1){ // Esc key on keyboard printf("Esc key\n"); goto out; } if (scode == LSHIFT || scode == RSHIFT){ shifted = 1; // set shifted flag goto out; } if (scode == ALT){ alt = 1; goto out; } if (scode == CONTROL){ control = 1; goto out; } if (scode == 0x3A){ capslock = 1 - capslock; // capslock key acts like a toggle goto out; } if (control && alt && scode == DEL){ printf("3-finger salute\n"); goto out; } /************ 5-06-****** add F keys for debuggin *************/ if (scode == F1){ printf("F1 key : "); do_ps(); goto out; } if (scode == F2){ printf("Function Key F2\n"); goto out; } // translate scan code to ASCII, using shift[ ] table if shifted; c = (shifted ? shift[scode] : unshift[scode]); // Convert all to upper case if capslock is on if (capslock){ if (c >= 'A' && c <= 'Z') c += 'a' - 'A'; else if (c >= 'a' && c <= 'z') c -= 'a' - 'A'; } if (control && (c=='c'||c=='C')){ // Control-C keys on PC, these are 2 keys printf("Control-C Keys : Send INTR signal to process\n"); goto out; } if (control && (c=='d'|| c=='D')){ // Control-D, these are 2 keys printf("Control-D keys : set code=4 to let process hanlde KBD EOF\n"); c = 4; // Control-D } /* Store the character in kb.buf[] for process to get */ if (kb.data == KBLEN){ printf("%c\n", BELL); goto out; // kb.buf[] already FULL } kb.buf[kb.head++] = c; kb.head %= KBLEN; kb.data++; kwakeup(&kb.data); out: out_byte(0x20, 0x20); }
void main( void ) { do_ps(); }