// if the process exists, return 1. else 0. int mpm_proc_existp(int procid) { #if 0 struct process *procptr = getproc(procid); if (0 == procptr) { return 0; }; return 1; #else return (0 == getproc(procid)) ? 0 : 1; #endif }
int initialize() { int i, j; PROC *p; for (i=0; i < NPROC; i++){ p = &proc[i]; p->next = &proc[i+1]; p->pid = i; p->status = FREE; p->priority = 0; /*if (i){ // initialize kstack[ ] of proc[1] to proc[N-1] for (j=1; j<10; j++) p->kstack[SSIZE - j] = 0; // all saved registers = 0 p->kstack[SSIZE-1]=(int)body; // called tswitch() from body p->ksp = &(p->kstack[SSIZE-9]); // ksp -> kstack top }*/ } freeList = &proc[0]; running = getproc(); running->pid = 0; running->status = READY; running->priority = 0; readyQueue = 0; //proc[NPROC-1].next = freeList; // The last PROC item points to the front of the freeList printf("initialization complete\n"); }
static OSKIT_COMDECL filesystem_sync(oskit_filesystem_t *f, oskit_bool_t wait) { struct gfilesystem *fs = (struct gfilesystem *) f; struct mount *mp; struct proc *p; oskit_error_t ferror; int error, asyncflag; if (!fs || !fs->count || !fs->mp) return OSKIT_E_INVALIDARG; ferror = getproc(&p); if (ferror) return ferror; mp = fs->mp; error = 0; if ((mp->mnt_flag & (MNT_MLOCK|MNT_RDONLY|MNT_MPBUSY)) == 0 && !vfs_busy(mp)) { asyncflag = mp->mnt_flag & MNT_ASYNC; mp->mnt_flag &= ~MNT_ASYNC; error = VFS_SYNC(mp, wait ? MNT_WAIT : MNT_NOWAIT, p->p_ucred, p); if (asyncflag) mp->mnt_flag |= MNT_ASYNC; vfs_unbusy(mp); } prfree(p); if (error) return errno_to_oskit_error(error); return 0; }
int init() { int i,j; PROC *p; for (i=0; i<NPROC; i++){ p = &proc[i]; p->pid = i; p->status = FREE; p->pnext = p->next = &proc[i+1]; strcpy(p->name, tname[i]); printf("%d %s ", p->pid, proc[i % 4].name); } printf("\n"); proc[NPROC-1].next = 0; procList = freeList = &proc[0]; readyQueue = 0; // create and run P0 p = getproc(&freeList); p->pri = 0; p->status = READY; p->inkmode = 1; running = p; }
static OSKIT_COMDECL_U filesystem_release(oskit_filesystem_t *f) { struct gfilesystem *fs; struct proc *p; dev_t dev; int rc; unsigned newcount; fs = (struct gfilesystem*)f; if (fs == NULL) panic("%s:%d: null filesystem", __FILE__, __LINE__); if (fs->count == 0) panic("%s:%d: bad count", __FILE__, __LINE__); newcount = --fs->count; if (newcount == 0) { rc = getproc(&p); assert(rc == 0); if (fs->mp) { dev = ((struct ufsmount *)fs->mp->mnt_data)->um_dev; rc = dounmount(fs->mp, MNT_FORCE, p); assert(rc == 0); oskit_blkio_release((oskit_blkio_t *)dev); } prfree(p); free(fs,M_TEMP); } return newcount; }
error_t setup_proc_target (void) { error_t err; static task_t task; static process_t proc, target; static mach_msg_type_name_t targetType = MACH_MSG_TYPE_COPY_SEND; if (! MACH_PORT_VALID (proc)) proc = getproc (); if (MACH_PORT_VALID (task)) mach_port_deallocate (mach_task_self (), task); if (MACH_PORT_VALID (target)) mach_port_deallocate (mach_task_self (), target); err = task_create (mach_task_self (), 0, &task); if (err) return err; err = proc_task2proc (proc, task, &target); if (err) return err; return setup (target, targetType); }
int get_process_info_sysdep(ProcInfo_T p) { int nproc; int i,rv; struct userinfo user; memset(&user,0,sizeof(struct userinfo)); nproc=getproc(procs,NPROCS,sizeof(struct procinfo)); for(i=0;i<nproc;i++) { if(p->pid==procs[i].pi_pid) { if(procs[i].pi_stat==SZOMB) { empty: p->cputime_prev= p->cputime = 0; p->mem_kbyte= 0; p->mem_percent= 0.0; p->status_flag |= PROCESS_ZOMBIE; } else { rv=getuser(&(procs[i]),sizeof(struct procinfo), &user,sizeof(struct userinfo)); if(rv== -1) { goto empty; } p->mem_percent = user.ui_prm*10; p->mem_kbyte = (user.ui_drss+user.ui_trss)*4; p->cputime_prev= p->cputime; p->cputime= ( timestruc_to_tseconds(user.ui_ru.ru_utime) + timestruc_to_tseconds(user.ui_ru.ru_stime)); if( include_children ) { p->cputime+= ( timestruc_to_tseconds(user.ui_cru.ru_utime)+ timestruc_to_tseconds(user.ui_cru.ru_stime)); } /* first run ? */ if ( p->time_prev == 0.0 ) { p->cputime_prev= p->cputime; } } return TRUE; } } return FALSE; }
/* Change umask to ARGV[0] (octal value). Without arguments, print the value of current umask. */ error_t cmd_umask (pid_t pid, mach_port_t msgport, int argc, char *argv[]) { error_t err; mode_t umask; task_t task; process_t proc = getproc (); err = proc_pid2task (proc, pid, &task); if (err) return err; if (argc) { umask = strtol(argv[0], 0, 8); err = msg_set_init_int (msgport, task, INIT_UMASK, umask); } else { err = msg_get_init_int (msgport, task, INIT_UMASK, &umask); if (!err) printf ("%d: %03o\n", pid, umask); } mach_port_deallocate (mach_task_self (), task); return err; }
int main (int argc, char **argv) { struct ps_context *pc; mach_port_t bootstrap; error_t err; opt_clk_tck = OPT_CLK_TCK; opt_stat_mode = OPT_STAT_MODE; opt_fake_self = OPT_FAKE_SELF; opt_kernel_pid = OPT_KERNEL_PID; opt_anon_owner = OPT_ANON_OWNER; err = argp_parse (&argp, argc, argv, 0, 0, 0); if (err) error (1, err, "Could not parse command line"); err = ps_context_create (getproc (), &pc); if (err) error (1, err, "Could not create libps context"); task_get_bootstrap_port (mach_task_self (), &bootstrap); if (bootstrap == MACH_PORT_NULL) error (1, 0, "Must be started as a translator"); netfs_init (); err = root_make_node (pc, &netfs_root_node); if (err) error (1, err, "Could not create the root node"); netfs_startup (bootstrap, 0); netfs_server_loop (); assert (0 /* netfs_server_loop returned after all */); }
int send(unsigned int to, void *buffer, unsigned int len, struct proc_ctrl_blk *fr_p) { struct proc_ctrl_blk *to_p = getproc(to); struct proc_ctrl_blk *i; if (to_p->state == BLOCKED) { // ready to send blkcopy(to_p->buffer, buffer, MIN(len, to_p->buflen)); to_p->state = READY; return MIN(len, fr_p->buflen); } else if (to_p->state == READY) { fr_p->buffer = buffer; fr_p->buflen = len; // add to sender linked list i = to_p->sender; if (i != NULL) { for (; i->next != NULL; i = i->next); i->next = fr_p; } else to_p->sender = fr_p; return -1; // yield until ready } else { return -2; // bad pid specified } }
int main (int argc, char **argv) { error_t err; mach_port_t bootstrap; argp_parse (&argp, argc, argv, 0, 0, 0); if (MACH_PORT_VALID (opt_device_master)) { err = open_console (opt_device_master); assert_perror (err); mach_port_deallocate (mach_task_self (), opt_device_master); } save_argv = argv; task_get_bootstrap_port (mach_task_self (), &bootstrap); if (bootstrap == MACH_PORT_NULL) error (2, 0, "Must be started as a translator"); /* Fetch our proc server port for easy use. If we are booting, it is not set yet and `getproc' returns MACH_PORT_NULL; we reset PROCSERVER in S_exec_init (below). */ procserver = getproc (); err = trivfs_add_port_bucket (&port_bucket); if (err) error (1, 0, "error creating port bucket"); err = trivfs_add_control_port_class (&trivfs_control_class); if (err) error (1, 0, "error creating control port class"); err = trivfs_add_protid_port_class (&trivfs_protid_class); if (err) error (1, 0, "error creating protid port class"); execboot_portclass = ports_create_class (deadboot, NULL); /* Reply to our parent. */ err = trivfs_startup (bootstrap, 0, trivfs_control_class, port_bucket, trivfs_protid_class, port_bucket, &fsys); /* Reply to our parent. */ err = trivfs_startup (bootstrap, 0, trivfs_control_class, port_bucket, trivfs_protid_class, port_bucket, &fsys); mach_port_deallocate (mach_task_self (), bootstrap); if (err) error (3, err, "Contacting parent"); /* Launch. */ ports_manage_port_operations_multithread (port_bucket, exec_demuxer, 2 * 60 * 1000, 0, 0); return 0; }
/***** showinfo */ static void showinfo(utmp_t *u, int formtype, int maxcmd, int from) { int jcpu, i, ut_pid_found; char uname[USERSZ + 1] = "", tty[5 + sizeof u->ut_line + 1] = "/dev/"; proc_t *best; for (i=0; i < sizeof u->ut_line; i++) /* clean up tty if garbled */ if (isalnum(u->ut_line[i]) || (u->ut_line[i]=='/')) tty[i+5] = u->ut_line[i]; else tty[i+5] = '\0'; best = getproc(u, tty + 5, &jcpu, &ut_pid_found); /* just skip if stale utmp entry (i.e. login proc doesn't exist). If there * is a desire a cmdline flag could be added to optionally show it with a * prefix of (stale) in front of cmd or something like that. */ if (!ut_pid_found) return; strncpy(uname, u->ut_user, USERSZ); /* force NUL term for printf */ if (formtype) { printf("%-9.8s%-9.8s", uname, u->ut_line); if (from) print_host(u->ut_host, sizeof u->ut_host); print_logintime(u->ut_time, stdout); if (*u->ut_line == ':') /* idle unknown for xdm logins */ printf(" ? "); else print_time_ival7(idletime(u, tty), 0, stdout); print_time_ival7(jcpu/Hertz, (jcpu%Hertz)*(100./Hertz), stdout); if (best) { int pcpu = best->utime + best->stime; print_time_ival7(pcpu/Hertz, (pcpu%Hertz)*(100./Hertz), stdout); } else printf(" ? "); } else { printf("%-9.8s%-9.8s", u->ut_user, u->ut_line); if (from) print_host(u->ut_host, sizeof u->ut_host); if (*u->ut_line == ':') /* idle unknown for xdm logins */ printf(" ? "); else print_time_ival7(idletime(u, tty), 0, stdout); } fputs(" ", stdout); if (best) { if (best->cmdline) print_strlist(stdout, best->cmdline, " ", maxcmd); else printf("%*.*s", -maxcmd, maxcmd, best->cmd); } else { printf("-"); } fputc('\n', stdout); }
kern_return_t S_exec_init (struct trivfs_protid *protid, auth_t auth, process_t proc) { mach_port_t host_priv, startup; error_t err; if (! protid || ! protid->isroot) return EPERM; _hurd_port_set (&_hurd_ports[INIT_PORT_PROC], proc); /* Consume. */ _hurd_port_set (&_hurd_ports[INIT_PORT_AUTH], auth); /* Consume. */ /* Do initial setup with the proc server. */ _hurd_proc_init (save_argv, NULL, 0); procserver = getproc (); /* Have the proc server notify us when the canonical ints and ports change. This will generate an immediate callback giving us the initial boot-time canonical sets. */ { struct iouser *user; struct trivfs_protid *cred; mach_port_t right; err = iohelp_create_empty_iouser (&user); assert_perror (err); err = trivfs_open (fsys, user, 0, MACH_PORT_NULL, &cred); assert_perror (err); right = ports_get_send_right (cred); proc_execdata_notify (procserver, right, MACH_MSG_TYPE_COPY_SEND); mach_port_deallocate (mach_task_self (), right); } err = get_privileged_ports (&host_priv, NULL); assert_perror (err); proc_register_version (procserver, host_priv, "exec", "", HURD_VERSION); err = proc_getmsgport (procserver, 1, &startup); assert_perror (err); mach_port_deallocate (mach_task_self (), procserver); /* Call startup_essential task last; init assumes we are ready to run once we call it. */ err = startup_essential_task (startup, mach_task_self (), MACH_PORT_NULL, "exec", host_priv); assert_perror (err); mach_port_deallocate (mach_task_self (), startup); mach_port_deallocate (mach_task_self (), host_priv); return 0; }
int mpm_getargv(int procid, int *ac, char ***av) { struct process *procptr = getproc(procid); if (0 == procptr) { return -1; }; *ac = procptr->ac; *av = procptr->av; return 0; }
static OSKIT_COMDECL filesystem_getroot(oskit_filesystem_t *f, struct oskit_dir **out_dir) { struct gfilesystem *fs = (struct gfilesystem *) f; oskit_dir_t *d; struct proc *p; oskit_error_t ferror; struct vnode *vp; int error; if (!fs || !fs->count || !fs->mp) return OSKIT_E_INVALIDARG; ferror = getproc(&p); if (ferror) return ferror; error = VFS_ROOT(fs->mp, &vp); if (error) { prfree(p); return errno_to_oskit_error(error); } error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p); if (error) { vput(vp); prfree(p); return errno_to_oskit_error(error); } d = (oskit_dir_t *) hashtab_search(vptab, (hashtab_key_t) vp); if (d) { oskit_dir_addref(d); } else { d = (oskit_dir_t *) gfile_create(fs,vp); if (!d) { vput(vp); prfree(p); return OSKIT_ENOMEM; } } vput(vp); prfree(p); *out_dir = d; return 0; }
int main (int argc, char **argv) { mach_port_t bootstrap; mach_port_t control; error_t err; /* Parse our options... */ argp_parse (&argp, argc, argv, 0, 0, 0); task_get_bootstrap_port (mach_task_self (), &bootstrap); if (bootstrap == MACH_PORT_NULL) error (1, 0, "Must be started as a translator"); linktarget = argv[1]; /* Reply to our parent */ mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, &control); mach_port_insert_right (mach_task_self (), control, control, MACH_MSG_TYPE_MAKE_SEND); err = fsys_startup (bootstrap, 0, control, MACH_MSG_TYPE_COPY_SEND, &realnode); mach_port_deallocate (mach_task_self (), control); mach_port_deallocate (mach_task_self (), bootstrap); if (err) error (1, err, "Starting up translator"); io_restrict_auth (realnode, &realnodenoauth, 0, 0, 0, 0); mach_port_deallocate (mach_task_self (), realnode); /* Mark us as important. */ mach_port_t proc = getproc (); if (proc == MACH_PORT_NULL) error (2, err, "cannot get a handle to our process"); err = proc_mark_important (proc); /* This might fail due to permissions or because the old proc server is still running, ignore any such errors. */ if (err && err != EPERM && err != EMIG_BAD_ID) error (2, err, "Cannot mark us as important"); mach_port_deallocate (mach_task_self (), proc); /* Launch */ while (1) { /* The timeout here is 10 minutes */ err = mach_msg_server_timeout (fsys_server, 0, control, MACH_RCV_TIMEOUT, 1000 * 60 * 10); if (err == MACH_RCV_TIMED_OUT) exit (0); } }
int main (int argc, char **argv) { error_t err; mach_port_t bootstrap; struct argp argp = { 0, 0, 0, "Hurd standard exec server." }; argp_parse (&argp, argc, argv, 0, 0, 0); save_argv = argv; #ifdef BFD /* Put the Mach kernel's idea of what flavor of machine this is into the fake BFD against which architecture compatibility checks are made. */ err = bfd_mach_host_arch_mach (mach_host_self (), &host_bfd.arch_info->arch, &host_bfd.arch_info->mach); if (err) error (1, err, "Getting host architecture from Mach"); #endif task_get_bootstrap_port (mach_task_self (), &bootstrap); if (bootstrap == MACH_PORT_NULL) error (2, 0, "Must be started as a translator"); /* Fetch our proc server port for easy use. If we are booting, it is not set yet and `getproc' returns MACH_PORT_NULL; we reset PROCSERVER in S_exec_init (below). */ procserver = getproc (); port_bucket = ports_create_bucket (); trivfs_cntl_portclasses[0] = ports_create_class (trivfs_clean_cntl, 0); trivfs_protid_portclasses[0] = ports_create_class (trivfs_clean_protid, 0); execboot_portclass = ports_create_class (deadboot, NULL); /* Reply to our parent. */ err = trivfs_startup (bootstrap, 0, trivfs_cntl_portclasses[0], port_bucket, trivfs_protid_portclasses[0], port_bucket, &fsys); mach_port_deallocate (mach_task_self (), bootstrap); if (err) error (3, err, "Contacting parent"); /* Launch. */ ports_manage_port_operations_multithread (port_bucket, exec_demuxer, 2 * 60 * 1000, 0, 0); return 0; }
static OSKIT_COMDECL filesystem_statfs(oskit_filesystem_t *f, oskit_statfs_t *out_stats) { struct gfilesystem *fs = (struct gfilesystem *) f; struct statfs *sp; struct mount *mp; struct proc *p; oskit_error_t ferror; int error; if (!fs || !fs->count || !fs->mp) return OSKIT_E_INVALIDARG; ferror = getproc(&p); if (ferror) return ferror; mp = fs->mp; sp = &mp->mnt_stat; error = VFS_STATFS(fs->mp, sp, p); prfree(p); if (error) return errno_to_oskit_error(error); sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK; out_stats->flag = 0; if (sp->f_flags & MNT_RDONLY) out_stats->flag |= OSKIT_FS_RDONLY; if (sp->f_flags & MNT_NOEXEC) out_stats->flag |= OSKIT_FS_NOEXEC; if (sp->f_flags & MNT_NOSUID) out_stats->flag |= OSKIT_FS_NOSUID; if (sp->f_flags & MNT_NODEV) out_stats->flag |= OSKIT_FS_NODEV; out_stats->bsize = sp->f_bsize; out_stats->frsize = sp->f_bsize; out_stats->blocks = sp->f_blocks; out_stats->bfree = sp->f_bfree; out_stats->bavail = sp->f_bavail; out_stats->files = sp->f_files; out_stats->ffree = sp->f_ffree; out_stats->favail = sp->f_ffree; out_stats->fsid = sp->f_fsid.val[0]; /* device number */ out_stats->namemax = NAME_MAX; return 0; }
/* Clear environment. */ error_t cmd_clearenv (pid_t pid, mach_port_t msgport, int argc, char *argv[]) { error_t err; task_t task; process_t proc = getproc (); err = proc_pid2task (proc, pid, &task); if (err) return err; err = msg_set_environment (msgport, task, 0, 0); mach_port_deallocate (mach_task_self (), task); return err; }
/* Set environment variable ARGV[0] to the value ARGV[1]. */ error_t cmd_setenv (pid_t pid, mach_port_t msgport, int argc, char *argv[]) { error_t err; task_t task; process_t proc = getproc (); err = proc_pid2task (proc, pid, &task); if (err) return err; err = msg_set_env_variable (msgport, task, argv[0], argv[1], 1); mach_port_deallocate (mach_task_self (), task); return err; }
/** * Read all processes of the proc files system to initilize * the process tree (sysdep version... but should work for * all procfs based unices) * @param reference reference of ProcessTree * @return treesize>0 if succeeded otherwise =0. */ int initprocesstree_sysdep(ProcessTree_T ** reference) { int treesize; int i,rv; struct userinfo user; ProcessTree_T * pt; memset(&user,0,sizeof(struct userinfo)); /* Find all processes in the system */ treesize=getproc(procs,NPROCS,sizeof(struct procinfo)); /* Allocate the tree */ pt = xcalloc(sizeof(ProcessTree_T), treesize); /* Insert data from /proc directory */ for(i=0;i<treesize;i++) { pt[i].pid=procs[i].pi_pid; pt[i].ppid=procs[i].pi_ppid; if(procs[i].pi_stat==SZOMB) { pt[i].mem_kbyte= 0; } else { rv=getuser(&(procs[i]),sizeof(struct procinfo), &user,sizeof(struct userinfo)); if(rv== -1) { pt[i].mem_kbyte= 0; } else { pt[i].mem_kbyte = (user.ui_drss+user.ui_trss)*4; } } } * reference = pt; return treesize; }
/* Set port associated to file descriptor FD of process PID, whose message port is MSGPORT, to FILE. Used by cmd_{setfd,stdin,stdout,stderr}. */ error_t do_setfd (pid_t pid, mach_port_t msgport, size_t fd, file_t file) { error_t err; task_t task; process_t proc = getproc (); err = proc_pid2task (proc, pid, &task); if (err) return err; err = msg_set_fd (msgport, task, fd, file, MACH_MSG_TYPE_COPY_SEND); mach_port_deallocate (mach_task_self (), file); mach_port_deallocate (mach_task_self (), task); return err; }
void mpm_procinit1(int procid) { struct process *procptr = getproc(procid); setPOIDm(procid); void *(*f)(int, char **); //fprintf(stderr, "pass1: ");printsyment(); //fprintf(stderr, "pass1-: ");printsyment(); #if 1 procptr->mdata = (*procptr->app->minit)(procptr->ac, procptr->av); #else f = procptr->app->minit; procptr->mdata = (*f)(0, 0); #endif procptr->initialized = 1; }
// returns the number of syscalls a process has made // lab1-1 int sys_callcount(void) { int pid; struct proc* p; if(argint(0, &pid) < 0) { return -1; } p = getproc(pid); if (p != (void*)0) { cprintf("%s has %d calls\n", p->name, p->callcount); return p->callcount; } else { return -1; } }
/* Execute command CMD on process PID */ error_t do_cmd (pid_t pid, cmd_t cmd) { error_t err; mach_port_t msgport; process_t proc = getproc (); /* Get a msgport for PID, to which we can send requests. */ err = proc_getmsgport (proc, pid, &msgport); if (err) error (1, err, "%d: Cannot get process msgport", pid); err = (*cmd.f) (pid, msgport, cmd.num_args, cmd.args); if (err) error (2, err, "%d: Cannot execute command", pid); mach_port_deallocate (mach_task_self (), msgport); return 0; }
static OSKIT_COMDECL filesystem_unmount(oskit_filesystem_t *f) { struct gfilesystem *fs = (struct gfilesystem *) f; struct mount *mp; dev_t dev; struct proc *p; oskit_error_t ferror; int error; if (!fs || !fs->count || !fs->mp) return OSKIT_E_INVALIDARG; ferror = getproc(&p); if (ferror) return ferror; mp = fs->mp; /* * Only root, or the user that did the original mount is * permitted to forcibly unmount it. */ if (mp->mnt_stat.f_owner != p->p_ucred->cr_uid && (error = suser(p->p_ucred, 0))) { prfree(p); return errno_to_oskit_error(error); } /* Get the blkio "pointed" to by the dev_t so we can release it below. */ dev = ((struct ufsmount *)mp->mnt_data)->um_dev; error = dounmount(fs->mp, MNT_FORCE, p); fs->mp = 0; prfree(p); oskit_blkio_release((oskit_blkio_t *)dev); if (error) return errno_to_oskit_error(error); return 0; }
void prefork(LinkList list, int flags) { LinkNode node; MUSTUSEHEAP("prefork"); for (node = firstnode(list); node; incnode(node)) { char *str, *str3; str = str3 = (char *)getdata(node); if ((*str == Inang || *str == Outang || *str == Equals) && str[1] == Inpar) { if (*str == Inang || *str == Outang) setdata(node, (void *) getproc(str)); /* <(...) or >(...) */ else setdata(node, (void *) getoutputfile(str)); /* =(...) */ if (!getdata(node)) return; } else { if (isset(SHFILEEXPANSION)) filesub((char **)getaddrdata(node), flags & 3); if (!(node = stringsubst(list, node, flags & 4))) return; } } for (node = firstnode(list); node; incnode(node)) { if (*(char *)getdata(node)) { remnulargs(getdata(node)); if (unset(IGNOREBRACES) && !(flags & 4)) while (hasbraces(getdata(node))) xpandbraces(list, &node); if (unset(SHFILEEXPANSION)) filesub((char **)getaddrdata(node), flags & 3); } else if (!(flags & 4)) uremnode(list, node); if (errflag) return; } }
int main (int argc, char **argv) { int opt; error_t err; fsys_t ctl_port; int pid = 0; process_t proc_server = getproc(); while ((opt = getopt_long(argc, argv, SHORT_OPTIONS, options, 0)) != EOF) switch (opt) { case 'p': /* Watch pid N */ pid = atoi(optarg); if (pid == 0) error(1, 0, "%s: Bad process id", optarg); break; default: usage(-1); } if (pid == 0) /* By default watch the top of the current login collection. */ { err = proc_getloginid(proc_server, getpid(), &pid); if (err) error(2, err, "Couldn't get current login collection"); } /* Setup a watch on the process we're interested in. */ err = proc_pid2proc(proc_server, pid, &watched_process); if (err) error(3, err, "Couldn't get process port for watched process"); _libports_initialize (); ctl_port = trivfs_handle_port(MACH_PORT_NULL, PT_CTL, PT_NODE); }
int kfork(){ /* PROC *p = getproc(); // get a FREE proc from freeList if (p==0) return -1; // no more PROCs in freeList -------------------------------------------------------- initialize p's ppid initialize p's kstack[] AS IF it called tswitch() before enter p into readyQueue (by priority) return p->pid */ int j; PROC *p = getproc(); // Set up a new PROC that points to the next free PROC in the list if(p==0) { printf("NO MORE LEFT TO GIVE\n"); return -1; } p->ppid = running->pid; // Set the parent PID to the PID of the running proc p->parent = running; p->status = READY; p->priority = 1; p->next = 0; //clear all saved registers on stack for(j=1; j<10; j++){ p->kstack[SSIZE-j] = 0; } //fill in resume p->kstack[SSIZE-1] = (int)body; p->ksp = &(p->kstack[SSIZE-9]); enqueue(p, &readyQueue); return p->pid; }
/* Print current root directory */ error_t cmd_getroot (pid_t pid, mach_port_t msgport, int argc, char *argv[]) { error_t err; file_t dir; task_t task; process_t proc = getproc (); err = proc_pid2task (proc, pid, &task); if (err) return err; err = msg_get_init_port (msgport, task, INIT_PORT_CRDIR, &dir); if (err) { mach_port_deallocate (mach_task_self (), task); return err; } printf ("%d: %s\n", pid, _hurd_canonicalize_directory_name_internal(dir, NULL, 0)); mach_port_deallocate (mach_task_self (), dir); mach_port_deallocate (mach_task_self (), task); return 0; }