main(int argc, char *argv[]) { char name[64]; int pid, cmd, segment, i; while(1){ pid = getpid(); segment = (pid+1)*0x1000; color = 0x0000B + (pid % 5); printf("==============================================\n"); printf("Das ist Prozess %d in der U Weise: Segment=%x\n", pid,segment); show_menu(); printf("Command ? "); gets(name); if (name[0]==0) continue; cmd = find_cmd(name); switch(cmd){ case 0 : getpid(); break; case 1 : ps(); break; case 2 : chname(); break; case 3 : kmode(); break; case 4 : kswitch(); break; case 5 : wait(); break; case 6 : exit(); break; case 7 : fork(); break; case 8 : exec(); break; case 9 : do_vfork(); break; default: invalid(name); break; } } }
int main(int argc, char** argv) { #if HAVE_DECL_PTRACE_SETOPTIONS && HAVE_DECL_PTRACE_O_TRACEVFORKDONE int exit_status; _parse_opts(argc, argv); if (fp == NULL) { fp = stderr; } if (socketpair(AF_UNIX, SOCK_STREAM, 0, psync) == -1) { tst_resm(TBROK | TERRNO, "socketpair() failed"); } else { child = fork(); if (child == -1) { tst_resm(TBROK | TERRNO, "fork() failed"); } else if (child == 0) { int rc = EXIT_FAILURE; tst_sig(FORK, DEF_HANDLER, child_cleanup); if (close(psync[1])) { tst_resm(TBROK, "close(psync[1]) failed)"); } else { /* sleep until the parent wakes us up */ await_mutex(psync[0]); rc = do_vfork(num_vforks); } _exit(rc); } else { tst_sig(FORK, kill_child, parent_cleanup); close(psync[0]); /* Set up ptrace */ if (ptrace(PTRACE_ATTACH, child, NULL, NULL) == -1) { tst_resm(TBROK | TERRNO, "ptrace(ATTACH) failed"); tst_exit(); } if (waitpid(child, NULL, 0) != child) { tst_resm(TBROK | TERRNO, "waitpid(%d) failed", child); kill_child(); } else { if (ptrace(PTRACE_SETOPTIONS, child, NULL, PTRACE_O_TRACEVFORK) == -1) { tst_resm(TINFO | TERRNO, "ptrace(PTRACE_SETOPTIONS) " "failed."); } if (ptrace(PTRACE_CONT, child, NULL, NULL) == -1) { tst_resm(TINFO | TERRNO, "ptrace(PTRACE_CONT) failed."); } send_mutex(psync[1]); close(psync[1]); tst_resm(TINFO, "Child spawn's pid=%d", child); fprintf(fp, "%d\n", child); fflush(fp); exit_status = do_trace(child, ++num_vforks); tst_resm(exit_status == 0 ? TPASS : TFAIL, "do_trace %s", (exit_status == 0 ? "succeeded" : "failed")); parent_cleanup(); } } } #else tst_resm(TCONF, "System doesn't support have required ptrace " "capabilities."); #endif tst_resm(TINFO, "Exiting..."); tst_exit(); }