您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ sys_waitpid函数代码示例

51自学网 2021-06-03 08:37:38
  C++
这篇教程C++ sys_waitpid函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中sys_waitpid函数的典型用法代码示例。如果您正苦于以下问题:C++ sys_waitpid函数的具体用法?C++ sys_waitpid怎么用?C++ sys_waitpid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了sys_waitpid函数的27个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: continue_or_step

static void continue_or_step(struct context* ctx, int stepi){	pid_t tid = ctx->child_tid;	if (stepi) {		sys_ptrace_singlestep(tid);	} else {		/* We continue with PTRACE_SYSCALL for error checking:		 * since the next event is supposed to be a signal,		 * entering a syscall here means divergence.  There		 * shouldn't be any straight-line execution overhead		 * for SYSCALL vs. CONT, so the difference in cost		 * should be neglible. */		sys_ptrace_syscall(tid);	}	sys_waitpid(tid, &ctx->status);	ctx->child_sig = signal_pending(ctx->status);	if (0 == ctx->child_sig) {		struct user_regs_struct regs;		read_child_registers(ctx->child_tid, &regs);		log_err("Replaying `%s' (line %d): expecting tracee signal or trap, but instead at `%s' (rcb: %llu)",			strevent(ctx->trace.stop_reason),			get_trace_file_lines_counter(),			strevent(regs.orig_eax), read_rbc(ctx->hpc));		emergency_debug(ctx);	}}
开发者ID:smillaedler,项目名称:rr,代码行数:29,


示例2: cont_syscall_boundary

/** * Continue until reaching either the "entry" of an emulated syscall, * or the entry or exit of an executed syscall.  |emu| is nonzero when * we're emulating the syscall.  Return 0 when the next syscall * boundary is reached, or nonzero if advancing to the boundary was * interrupted by an unknown trap. */static int cont_syscall_boundary(struct context* ctx, int emu, int stepi){	pid_t tid = ctx->child_tid;	if (emu && stepi) {		sys_ptrace_sysemu_singlestep(tid);	} else if (emu) {		sys_ptrace_sysemu(tid);	} else if (stepi) {		sys_ptrace_singlestep(tid);	} else {		sys_ptrace_syscall(tid);	}	sys_waitpid(tid, &ctx->status);	switch ((ctx->child_sig = signal_pending(ctx->status))) {	case 0:		break;	case SIGCHLD:		/* SIGCHLD is pending, do not deliver it, wait for it		 * to appear in the trace SIGCHLD is the only signal		 * that should ever be generated as all other signals		 * are emulated! */		return cont_syscall_boundary(ctx, emu, stepi);	case SIGTRAP:		return 1;	default:		log_err("Replay got unrecorded signal %d", ctx->child_sig);		emergency_debug(ctx);	}	assert(ctx->child_sig == 0);	return 0;}
开发者ID:smillaedler,项目名称:rr,代码行数:42,


示例3: common_prog

/* * Common code for cmd_prog and cmd_shell. * * Note that this does not wait for the subprogram to finish, but * returns immediately to the menu. This is usually not what you want, * so you should have it call your system-calls-assignment waitpid * code after forking. * * Also note that because the subprogram's thread uses the "args" * array and strings, until you do this a race condition exists * between that code and the menu input code. */staticintcommon_prog(int nargs, char **args){	int result;#if OPT_SYNCHPROBS	kprintf("Warning: this probably won't work with a "		"synchronization-problems kernel./n");#endif		struct thread *thread_runs;	result = thread_fork(args[0] /* thread name */,			cmd_progthread /* thread function */,			args /* thread arg */, nargs /* thread arg */,			&thread_runs);	int status = S_ZOMBIE;	int wait_return;	sys_waitpid(thread_runs->pid,&status,0,&wait_return);		if (result) {		kprintf("thread_fork failed: %s/n", strerror(result));		return result;	}	return 0;}
开发者ID:Relmont,项目名称:OS161-kernel,代码行数:39,


示例4: common_prog

/* * Common code for cmd_prog and cmd_shell. * * Note that this does not wait for the subprogram to finish, but * returns immediately to the menu. This is usually not what you want, * so you should have it call your system-calls-assignment waitpid * code after forking. * * Also note that because the subprogram's thread uses the "args" * array and strings, until you do this a race condition exists * between that code and the menu input code. */staticint common_prog(int nargs, char **args) {	int result;	int x;	pid_t retval;	struct thread *curthread;	curthread = kmalloc(sizeof(struct thread*));#if OPT_SYNCHPROBS	kprintf("Warning: this probably won't work with a "			"synchronization-problems kernel./n");#endif	result = thread_fork(args[0] /* thread name */,			cmd_progthread /* thread function */, args /* thread arg */,			nargs /* thread arg */, &curthread );	if (result) {		kprintf("thread_fork failed: %s/n", strerror(result));		return result;	}	//call wait pid code - need to change//	curthread->t_sem = sem_create("curthread",0);	//P(curthread->t_sem);	if(sys_waitpid(curthread->t_pid,&x,0,&retval)){		return 0;	}	return 0;}
开发者ID:krnprdp,项目名称:os161-src,代码行数:42,


示例5: prefork_cleanup_loop

static void prefork_cleanup_loop(struct prefork_pool *pfp){	int status;	pid_t pid;	int i;	/* TODO: should we use a process group id wait instead of looping ? */	for (i = 0; i < pfp->pool_size; i++) {		if (pfp->pool[i].status == PF_WORKER_NONE ||		    pfp->pool[i].pid == 0) {			continue;		}		pid = sys_waitpid(pfp->pool[i].pid, &status, WNOHANG);		if (pid > 0) {			if (pfp->pool[i].status != PF_WORKER_EXITING) {				DEBUG(3, ("Child (%d) terminated abnormally:"					  " %d/n", (int)pid, status));			} else {				DEBUG(10, ("Child (%d) terminated with status:"					   " %d/n", (int)pid, status));			}			/* reset all fields,			 * this makes status = PF_WORK_NONE */			memset(&pfp->pool[i], 0,				sizeof(struct pf_worker_data));		}	}}
开发者ID:AIdrifter,项目名称:samba,代码行数:32,


示例6: kt_kernel_idle_task

int kt_kernel_idle_task(void){	tm_thread_raise_flag(current_thread, THREAD_KERNEL);	kthread_create(&kthread_pager, "[kpager]", 0, __KT_pager, 0);	strncpy((char *)current_process->command, "[kernel]", 128);	/* wait until init has successfully executed, and then remap. */	while(!(kernel_state_flags & KSF_HAVEEXECED)) {		tm_schedule();	}	printk(1, "[kernel]: remapping lower memory with protection flags.../n");	cpu_interrupt_set(0);	for(addr_t addr = MEMMAP_KERNEL_START; addr < MEMMAP_KERNEL_END; addr += PAGE_SIZE)	{		mm_virtual_changeattr(addr, PAGE_PRESENT | PAGE_WRITE, PAGE_SIZE);	}	cpu_interrupt_set(1);	/* Now enter the main idle loop, waiting to do periodic cleanup */	printk(0, "[idle]: entering background loop/n");	for(;;) {		assert(!current_thread->held_locks);		int r=1;		if(__current_cpu->work.count > 0)			r=workqueue_dowork(&__current_cpu->work);		else			tm_schedule();		int status;		int pid = sys_waitpid(-1, &status, WNOHANG);		if(WIFSTOPPED(status)) {			sys_kill(pid, SIGKILL);		}	}}
开发者ID:AshishKumar4,项目名称:seakernel,代码行数:32,


示例7: singlestep

static void singlestep(struct context *ctx, int sig, int expected_val){	sys_ptrace_singlestep(ctx->child_tid, sig);	sys_waitpid(ctx->child_tid, &ctx->status);	/* we get a simple SIGTRAP in this case */	if (ctx->status != expected_val) {		printf("status %x   expected %x/n", ctx->status, expected_val);	}	assert(ctx->status == expected_val);	ctx->status = 0;	ctx->child_sig = 0;}
开发者ID:sanyaade-mobiledev,项目名称:rr,代码行数:13,


示例8: winbindd_sig_chld_handler

static void winbindd_sig_chld_handler(struct tevent_context *ev,				      struct tevent_signal *se,				      int signum,				      int count,				      void *siginfo,				      void *private_data){	pid_t pid;	while ((pid = sys_waitpid(-1, NULL, WNOHANG)) > 0) {		winbind_child_died(pid);	}}
开发者ID:rti7743,项目名称:samba,代码行数:13,


示例9: step_exit_syscall_emu

/** *  Step over the system call instruction to "exit" the emulated *  syscall. */static void step_exit_syscall_emu(struct context *ctx){	pid_t tid = ctx->child_tid;	struct user_regs_struct regs;	read_child_registers(tid, &regs);	sys_ptrace_sysemu_singlestep(tid);	sys_waitpid(tid, &ctx->status);	write_child_registers(tid, &regs);	ctx->status = 0;}
开发者ID:smillaedler,项目名称:rr,代码行数:18,


示例10: sig_cld

static void sig_cld(int signum){	while (sys_waitpid((pid_t)-1,(int *)NULL, WNOHANG) > 0)		;	/*	 * Turns out it's *really* important not to	 * restore the signal handler here if we have real POSIX	 * signal handling. If we do, then we get the signal re-delivered	 * immediately - hey presto - instant loop ! JRA.	 */#if !defined(HAVE_SIGACTION)	CatchSignal(SIGCLD, sig_cld);#endif}
开发者ID:DeezNuts12,项目名称:freestyledash,代码行数:16,


示例11: goto_next_event

void goto_next_event(struct context *ctx){	if (ctx->child_sig != 0) {		printf("sending signal: %d/n",ctx->child_sig);	}	sys_ptrace(PTRACE_SYSCALL, ctx->child_tid, 0, (void*) ctx->child_sig);	sys_waitpid(ctx->child_tid, &ctx->status);	ctx->child_sig = signal_pending(ctx->status);	if (ctx->child_sig == SIGTRAP) {		log_err("Caught unexpected SIGTRAP while going to next event");		emergency_debug(ctx);	}	ctx->event = read_child_orig_eax(ctx->child_tid);}
开发者ID:smillaedler,项目名称:rr,代码行数:16,


示例12: common_prog

/* * Common code for cmd_prog and cmd_shell. * * Note that this does not wait for the subprogram to finish, but * returns immediately to the menu. This is usually not what you want, * so you should have it call your system-calls-assignment waitpid * code after forking. * * Also note that because the subprogram's thread uses the "args" * array and strings, until you do this a race condition exists * between that code and the menu input code. */staticintcommon_prog(int nargs, char **args){	struct proc *proc;	int result;	int status;	int retval;	unsigned tc;	/* Create a process for the new program to run in. */	proc = proc_create_runprogram(args[0] /* name */);	if (proc == NULL) {		return ENOMEM;	}	tc = thread_count;	result = thread_fork(args[0] /* thread name */,			proc /* new process */,			cmd_progthread /* thread function */,			args /* thread arg */, nargs /* thread arg */);	if (result) {		kprintf("thread_fork failed: %s/n", strerror(result));		proc_destroy(proc);		return result;	}	result = sys_waitpid(proc->pid, &status, 0 , &retval);	if (result ) {		kprintf_n("sys_waitpid done with result %d for pid %d /n",result,proc->pid );		//return 0;	}	/*	 * The new process will be destroyed when the program exits...	 * once you write the code for handling that.	 */	// Wait for all threads to finish cleanup, otherwise khu be a bit behind,	// especially once swapping is enabled.	thread_wait_for_count(tc);	return 0;}
开发者ID:prasad223,项目名称:os161_Docker,代码行数:59,


示例13: interpret_pipe

static void interpret_pipe(struct interpreter_context *context, struct ast_node *node){    struct gsh_command *cmd1 = node->n_children;    struct gsh_command *cmd2 = node->n_children->next;        int in = sys_fcntl(0, 0, 0, 0);    int out = sys_fcntl(1, 0, 0, 0);    int err = sys_fcntl(2, 0, 0, 0);        int pipe_des[2];    sys_pipe(pipe_des);        close(0);    sys_fcntl(pipe_des[0], 0, 0, 0);    int pid = interpret_cmd(context, cmd2, P_NOWAIT);        close(0);    close(1);    close(2);        sys_fcntl(in, 0, 0, 0);    sys_fcntl(pipe_des[1], 0, 1, 0);    sys_fcntl(pipe_des[1], 0, 2, 0);        interpret_cmd(context, cmd1, P_WAIT);            close(1);    close(2);            sys_fcntl(out, 0, 1, 0);    sys_fcntl(err, 0, 2, 0);        close(pipe_des[0]);    close(pipe_des[1]);        int status;    sys_waitpid(pid, &status);        close(out);    close(err);}
开发者ID:GruntTheDivine,项目名称:infinity,代码行数:44,


示例14: common_prog

staticintcommon_prog(int nargs, char **args){	struct proc *proc;	int result;#if OPT_SYNCHPROBS	kprintf("Warning: this probably won't work with a "		"synchronization-problems kernel./n");#endif	/* Create a process for the new program to run in. */	proc = proc_create_runprogram(args[0] /* name */);	if (proc == NULL) {		return ENOMEM;	}	result = thread_fork(args[0] /* thread name */,			proc /* new process */,			cmd_progthread /* thread function */,			args /* thread arg */, nargs /* thread arg */);	if (result) {		kprintf("thread_fork failed: %s/n", strerror(result));		proc_destroy(proc);		return result;	}	/*	 * The new process will be destroyed when the program exits...	 * once you write the code for handling that.	 */ 	int *status = kmalloc(sizeof(int));	sys_waitpid(proc->p_pid, status, 0);	return 0;}
开发者ID:y3046308,项目名称:os-group-project,代码行数:38,


示例15: signal_handle

int signal_handle(struct task *current, struct irq_frame *iframe){    while (current->sig_pending & (~current->sig_blocked)) {        int signum = bit32_find_first_set((current->sig_pending & (~current->sig_blocked))) + 1;        struct sigaction *action = current->sig_actions + signum - 1;        kp(KP_TRACE, "signal: Handling %d on %d/n", signum, current->pid);        kp(KP_TRACE, "signal: Handler: %p/n", action->sa_handler);        SIGSET_UNSET(&current->sig_pending, signum);        if (action->sa_handler == SIG_IGN) {            if (signum == SIGCHLD) {                while (sys_waitpid(-1, NULL, WNOHANG) > 0)                    /* Reap chlidren */;            }            continue;        } else if (action->sa_handler == SIG_DFL) {            signal_default(current, signum);        } else {            signal_jump(current, signum, iframe);            return 1;        }    }    if (current->context.prev_syscall) {        switch (iframe->eax) {        case -ERESTARTSYS:        case -ERESTARTNOINTR:        case -ERESTARTNOHAND:            signal_syscall_restart(iframe, current->context.prev_syscall);            break;        }    }    return 0;}
开发者ID:DSMan195276,项目名称:protura,代码行数:37,


示例16: sys_pclose

int sys_pclose(int fd){	int wstatus;	popen_list **ptr = &popen_chain;	popen_list *entry = NULL;	pid_t wait_pid;	int status = -1;	/* Unlink from popen_chain. */	for ( ; *ptr != NULL; ptr = &(*ptr)->next) {		if ((*ptr)->fd == fd) {			entry = *ptr;			*ptr = (*ptr)->next;			status = 0;			break;		}	}	if (status < 0 || close(entry->fd) < 0)		return -1;	/*	 * As Samba is catching and eating child process	 * exits we don't really care about the child exit	 * code, a -1 with errno = ECHILD will do fine for us.	 */	do {		wait_pid = sys_waitpid (entry->child_pid, &wstatus, 0);	} while (wait_pid == -1 && errno == EINTR);	SAFE_FREE(entry);	if (wait_pid == -1)		return -1;	return wstatus;}
开发者ID:WiseMan787,项目名称:ralink_sdk,代码行数:37,


示例17: compat_sys_waitpid

/* Note: it is necessary to treat pid and options as unsigned ints, * with the corresponding cast to a signed int to insure that the  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */asmlinkage long compat_sys_waitpid(u32 pid, unsigned int __user * stat_addr, u32 options){	return sys_waitpid((int)pid, stat_addr, (int)options);}
开发者ID:openube,项目名称:android_kernel_sony_c2305,代码行数:9,


示例18: syscall_dispatch

static int syscall_dispatch(uint32_t sysnum, uint32_t args, regs_t *regs){    switch (sysnum) {        case SYS_waitpid:            return sys_waitpid((waitpid_args_t *)args);                    case SYS_exit:            do_exit((int)args);            panic("exit failed!/n");            return 0;                    case SYS_thr_exit:            kthread_exit((void *)args);            panic("thr_exit failed!/n");            return 0;                    case SYS_thr_yield:            sched_make_runnable(curthr);            sched_switch();            return 0;                    case SYS_fork:            return sys_fork(regs);                    case SYS_getpid:            return curproc->p_pid;                    case SYS_sync:            sys_sync();            return 0;            #ifdef __MOUNTING__        case SYS_mount:            return sys_mount((mount_args_t *) args);                    case SYS_umount:            return sys_umount((argstr_t *) args);#endif                    case SYS_mmap:            return (int) sys_mmap((mmap_args_t *) args);                    case SYS_munmap:            return sys_munmap((munmap_args_t *) args);                    case SYS_open:            return sys_open((open_args_t *) args);                    case SYS_close:            return sys_close((int)args);                    case SYS_read:            return sys_read((read_args_t *)args);                    case SYS_write:            return sys_write((write_args_t *)args);                    case SYS_dup:            return sys_dup((int)args);                    case SYS_dup2:            return sys_dup2((dup2_args_t *)args);                    case SYS_mkdir:            return sys_mkdir((mkdir_args_t *)args);                    case SYS_rmdir:            return sys_rmdir((argstr_t *)args);                    case SYS_unlink:            return sys_unlink((argstr_t *)args);                    case SYS_link:            return sys_link((link_args_t *)args);                    case SYS_rename:            return sys_rename((rename_args_t *)args);                    case SYS_chdir:            return sys_chdir((argstr_t *)args);                    case SYS_getdents:            return sys_getdents((getdents_args_t *)args);                    case SYS_brk:            return (int) sys_brk((void *)args);                    case SYS_lseek:            return sys_lseek((lseek_args_t *)args);                    case SYS_halt:            sys_halt();            return -1;                    case SYS_set_errno:            curthr->kt_errno = (int)args;            return 0;                    case SYS_errno:            return curthr->kt_errno;//.........这里部分代码省略.........
开发者ID:ketapate,项目名称:kernel_3,代码行数:101,


示例19: start

/** * main replayer method */static void start(int option, int argc, char* argv[], char** envp){	pid_t pid;	int status, fake_argc;	if (option == RECORD) {		copy_executable(argv[2]);		if (access(__executable, X_OK)) {			printf("The specified file '%s' does not exist or is not executable/n", __executable);			return;		}		/* create directory for trace files */		setup_trace_dir(0);		/* initialize trace files */		open_trace_files();		init_trace_files();		copy_argv(argc, argv);		copy_envp(envp);		record_argv_envp(argc, __argv, __envp);		close_trace_files();		pid = sys_fork();		/* child process */		if (pid == 0) {			sys_start_trace(__executable, __argv, __envp);			/* parent process */		} else {			child = pid;			/* make sure that the child process dies when the master process gets interrupted */			install_signal_handler();			/* sync with the child process */			sys_waitpid(pid, &status);			/* configure the child process to get a message upon a thread start, fork(), etc. */			sys_ptrace_setup(pid);			/* initialize stuff */			init_libpfm();			/* initialize the trace file here -- we need to record argc and envp */			open_trace_files();			/* register thread at the scheduler and start the HPC */			rec_sched_register_thread(0, pid);			/* perform the action recording */			fprintf(stderr, "start recording.../n");			start_recording();			fprintf(stderr, "done recording -- cleaning up/n");			/* cleanup all initialized data-structures */			close_trace_files();			close_libpfm();		}		/* replayer code comes here */	} else if (option == REPLAY) {		init_environment(argv[2], &fake_argc, __argv, __envp);		copy_executable(__argv[0]);		if (access(__executable, X_OK)) {			printf("The specified file '%s' does not exist or is not executable/n", __executable);			return;		}		pid = sys_fork();		//child process		if (pid == 0) {			sys_start_trace(__executable, __argv, __envp);			/* parent process */		} else {			child = pid;			/* make sure that the child process dies when the master process gets interrupted */			install_signal_handler();			sys_waitpid(pid, &status);			sys_ptrace_setup(pid);			/* initialize stuff */			init_libpfm();			rep_sched_init();			/* sets the file pointer to the first trace entry */			read_trace_init(argv[2]);			pid_t rec_main_thread = get_recorded_main_thread();			rep_sched_register_thread(pid, rec_main_thread);			/* main loop */			replay();			/* thread wants to exit*/			close_libpfm();			read_trace_close();			rep_sched_close();//.........这里部分代码省略.........
开发者ID:sanyaade-mobiledev,项目名称:rr,代码行数:101,


示例20: chat_with_program

static BOOL chat_with_program(char *passwordprogram,char *name,char *chatsequence, BOOL as_root){  char *slavedev;  int master;  pid_t pid, wpid;  int wstat;  BOOL chstat = False;      /* allocate a pseudo-terminal device */  if ((master = findpty (&slavedev)) < 0) {    DEBUG(3,("Cannot Allocate pty for password change: %s/n",name));    return(False);  }  /*   * We need to temporarily stop CatchChild from eating   * SIGCLD signals as it also eats the exit status code. JRA.   */  CatchChildLeaveStatus();  if ((pid = fork()) < 0) {    DEBUG(3,("Cannot fork() child for password change: %s/n",name));    close(master);    CatchChild();    return(False);  }  /* we now have a pty */  if (pid > 0){			/* This is the parent process */    if ((chstat = talktochild(master, chatsequence)) == False) {      DEBUG(3,("Child failed to change password: %s/n",name));      kill(pid, SIGKILL); /* be sure to end this process */    }	while((wpid = sys_waitpid(pid, &wstat, 0)) < 0) {      if(errno == EINTR) {        errno = 0;        continue;      }	  break;    }    if (wpid < 0) {      DEBUG(3,("The process is no longer waiting!/n/n"));      close(master);      CatchChild();      return(False);    }    /*     * Go back to ignoring children.     */    CatchChild();    close(master);    if (pid != wpid) {      DEBUG(3,("We were waiting for the wrong process ID/n"));	      return(False);    }    if (WIFEXITED(wstat) == 0) {      DEBUG(3,("The process exited while we were waiting/n"));      return(False);    }    if (WEXITSTATUS(wstat) != 0) {      DEBUG(3,("The status of the process exiting was %d/n", wstat));      return(False);    }      } else {    /* CHILD */    /*     * Lose any oplock capabilities.     */    set_process_capability(KERNEL_OPLOCK_CAPABILITY, False);    set_inherited_process_capability(KERNEL_OPLOCK_CAPABILITY, False);    /* make sure it doesn't freeze */    alarm(20);    if (as_root)      become_root(False);    DEBUG(3,("Dochild for user %s (uid=%d,gid=%d)/n",name,(int)getuid(),(int)getgid()));    chstat = dochild(master, slavedev, name, passwordprogram, as_root);	/*	 * The child should never return from dochild() ....	 */	DEBUG(0,("chat_with_program: Error: dochild() returned %d/n", chstat ));	exit(1);  }  if (chstat)    DEBUG(3,("Password change %ssuccessful for user %s/n", (chstat?"":"un"), name));  return (chstat);}
开发者ID:AllardJ,项目名称:Tomato,代码行数:99,


示例21: mips_syscall

voidmips_syscall(struct trapframe *tf){	int callno;	int32_t retval;	int err;	assert(curspl==0);	callno = tf->tf_v0;	/*	 * Initialize retval to 0. Many of the system calls don't	 * really return a value, just 0 for success and -1 on	 * error. Since retval is the value returned on success,	 * initialize it to 0 by default; thus it's not necessary to	 * deal with it except for calls that return other values, 	 * like write.	 */	retval = 0;	switch (callno) {	    case SYS_reboot:			err = sys_reboot(tf->tf_a0);			break;			    case SYS_getpid:			retval = ((int32_t)sys_getpid());			err=retval;			break;					case SYS_waitpid:			//just passing the the first arg from users waitpid			err = (sys_waitpid(tf->tf_a0,&retval,0));			break;				case SYS__exit:					retval = ((int32_t)sys__exit());			err=retval;			break;					case SYS_fork:			//http://jhshi.me/2012/03/21/os161-how-to-add-a-system-call/			err = ((int32_t)sys_fork(tf));			break;		case SYS_execv:			break;		case SYS_read:			//err = ((int32_t)sys_read(tf->tf_a0,(userptr_t)tf->tf_a1,tf->tf_a2)); //original			err = ((int32_t)sys_read(tf->tf_a0,(char*)tf->tf_a1,tf->tf_a2));			break;		case SYS_write:			err = ((int32_t)sys_write(tf->tf_a0,(char*)tf->tf_a1,tf->tf_a2));			break;	    default:		kprintf("Unknown syscall %d/n", callno);		err = ENOSYS;		break;	}	if (err) {		/*		 * Return the error code. This gets converted at		 * userlevel to a return value of -1 and the error		 * code in errno.		 */		tf->tf_v0 = err;		tf->tf_a3 = 1;      /* signal an error */	}	else {		/* Success. */		tf->tf_v0 = retval;		tf->tf_a3 = 0;      /* signal no error */	}		/*	 * Now, advance the program counter, to avoid restarting	 * the syscall over and over again.	 */		tf->tf_epc += 4;	/* Make sure the syscall code didn't forget to lower spl */	assert(curspl==0);}
开发者ID:Hle14,项目名称:ASST2,代码行数:89,


示例22: do_signal

/* * Note that 'init' is a special process: it doesn't get signals it doesn't * want to handle. Thus you cannot kill init even with a SIGKILL even by * mistake. * * Note that we go through the signals twice: once to check the signals * that the kernel can handle, and then we build all the user-level signal * handling stack-frames in one go after that. */asmlinkage int do_signal(unsigned long oldmask, struct pt_regs *regs){	unsigned long mask = ~current->blocked;	unsigned long signr;	struct sigaction * sa;	current->tss.esp0 = (unsigned long) regs;	/* If the process is traced, all signals are passed to the debugger. */	if (current->flags & PF_PTRACED)		mask = ~0UL;	while ((signr = current->signal & mask) != 0) {                signr = ffz(~signr);                clear_bit(signr, &current->signal);		sa = current->sig->action + signr;		signr++;#ifdef DEBUG		printk("Signal %d: ", sa->sa_handler);#endif		if ((current->flags & PF_PTRACED) && signr != SIGKILL) {			current->exit_code = signr;			current->state = TASK_STOPPED;			/* Did we come from a system call? */			if (regs->orig_d0 >= 0) {				/* Restart the system call */				if (regs->d0 == -ERESTARTNOHAND ||				    regs->d0 == -ERESTARTSYS ||				    regs->d0 == -ERESTARTNOINTR) {					regs->d0 = regs->orig_d0;					regs->pc -= 2;				}			}			notify_parent(current, SIGCHLD);			schedule();			if (!(signr = current->exit_code)) {			discard_frame:			    continue;			}			current->exit_code = 0;			if (signr == SIGSTOP)				goto discard_frame;			if (_S(signr) & current->blocked) {				current->signal |= _S(signr);				mask &= ~_S(signr);				continue;			}			sa = current->sig->action + signr - 1;		}		if (sa->sa_handler == SIG_IGN) {#ifdef DEBUG			printk("Ignoring./n");#endif			if (signr != SIGCHLD)				continue;			/* check for SIGCHLD: it's special */			while (sys_waitpid(-1,NULL,WNOHANG) > 0)				/* nothing */;			continue;		}		if (sa->sa_handler == SIG_DFL) {#ifdef DEBUG			printk("Default./n");#endif			if (current->pid == 1)				continue;			switch (signr) {			case SIGCONT: case SIGCHLD: case SIGWINCH:				continue;			case SIGTSTP: case SIGTTIN: case SIGTTOU:				if (is_orphaned_pgrp(current->pgrp))					continue;			case SIGSTOP:				if (current->flags & PF_PTRACED)					continue;				current->state = TASK_STOPPED;				current->exit_code = signr;				if (!(current->p_pptr->sig->action[SIGCHLD-1].sa_flags & 				      SA_NOCLDSTOP))					notify_parent(current, SIGCHLD);				schedule();				continue;			case SIGQUIT: case SIGILL: case SIGTRAP:			case SIGIOT: case SIGFPE: case SIGSEGV:				if (current->binfmt && current->binfmt->core_dump) {				    if (current->binfmt->core_dump(signr, regs))					signr |= 0x80;//.........这里部分代码省略.........
开发者ID:carlobar,项目名称:uclinux_leon3_UD,代码行数:101,


示例23: syscall

/* * System call dispatcher. * * A pointer to the trapframe created during exception entry (in * exception.S) is passed in. * * The calling conventions for syscalls are as follows: Like ordinary * function calls, the first 4 32-bit arguments are passed in the 4 * argument registers a0-a3. 64-bit arguments are passed in *aligned* * pairs of registers, that is, either a0/a1 or a2/a3. This means that * if the first argument is 32-bit and the second is 64-bit, a1 is * unused. * * This much is the same as the calling conventions for ordinary * function calls. In addition, the system call number is passed in * the v0 register. * * On successful return, the return value is passed back in the v0 * register, or v0 and v1 if 64-bit. This is also like an ordinary * function call, and additionally the a3 register is also set to 0 to * indicate success. * * On an error return, the error code is passed back in the v0 * register, and the a3 register is set to 1 to indicate failure. * (Userlevel code takes care of storing the error code in errno and * returning the value -1 from the actual userlevel syscall function. * See src/user/lib/libc/arch/mips/syscalls-mips.S and related files.) * * Upon syscall return the program counter stored in the trapframe * must be incremented by one instruction; otherwise the exception * return code will restart the "syscall" instruction and the system * call will repeat forever. * * If you run out of registers (which happens quickly with 64-bit * values) further arguments must be fetched from the user-level * stack, starting at sp+16 to skip over the slots for the * registerized values, with copyin(). */voidsyscall(struct trapframe *tf){    //kprintf("Starting syscall/n");	int callno;	int32_t retval;	int err;	KASSERT(curthread != NULL);	KASSERT(curthread->t_curspl == 0);	KASSERT(curthread->t_iplhigh_count == 0);	callno = tf->tf_v0;	/*	 * Initialize retval to 0. Many of the system calls don't	 * really return a value, just 0 for success and -1 on	 * error. Since retval is the value returned on success,	 * initialize it to 0 by default; thus it's not necessary to	 * deal with it except for calls that return other values, 	 * like write.	 */	retval = 0;	switch (callno) {	    case SYS_reboot:		err = sys_reboot(tf->tf_a0);		break;	    case SYS___time:		err = sys___time((userptr_t)tf->tf_a0,				 (userptr_t)tf->tf_a1);		break;#ifdef UW	case SYS_write:	  err = sys_write((int)tf->tf_a0,			  (userptr_t)tf->tf_a1,			  (int)tf->tf_a2,			  (int *)(&retval));	  break;	case SYS__exit:	  sys__exit((int)tf->tf_a0);	  /* sys__exit does not return, execution should not get here */	  panic("unexpected return from sys__exit");	  break;	case SYS_getpid:	  err = sys_getpid((pid_t *)&retval);	  break;	case SYS_waitpid:	  err = sys_waitpid((pid_t)tf->tf_a0,			    (userptr_t)tf->tf_a1,			    (int)tf->tf_a2,			    (pid_t *)&retval);	  break;	case SYS_fork:	    err = sys_fork(tf, (pid_t *)&retval);	    break;	case SYS_execv:	    err=sys_execv((char *)tf->tf_a0, (char **) tf->tf_a1);	    break;#endif // UW//.........这里部分代码省略.........
开发者ID:platky,项目名称:CS350-OS161,代码行数:101,


示例24: syscall

//.........这里部分代码省略......... * registerized values, with copyin(). */void syscall(struct trapframe *tf) {	int callno;	int32_t retval;	int err;	KASSERT(curthread != NULL);	KASSERT(curthread->t_curspl == 0);	KASSERT(curthread->t_iplhigh_count == 0);	callno = tf->tf_v0;	/*	 * Initialize retval to 0. Many of the system calls don't	 * really return a value, just 0 for success and -1 on	 * error. Since retval is the value returned on success,	 * initialize it to 0 by default; thus it's not necessary to	 * deal with it except for calls that return other values,	 * like write.	 */	retval = 0;	off_t pos, new_pos;	switch (callno) {	case SYS_reboot:		err = sys_reboot(tf->tf_a0);		break;	case SYS___time:		err = sys___time((userptr_t) tf->tf_a0, (userptr_t) tf->tf_a1);		break;	case SYS_open:		err = sys_open((userptr_t) tf->tf_a0, (int) tf->tf_a1,				(int) tf->tf_a2, &retval);		break;	case SYS_read:		err = sys_read((int) tf->tf_a0, (userptr_t) tf->tf_a1,				(int) tf->tf_a2, &retval);		break;	case SYS_write:		err = sys_write((int) tf->tf_a0, (userptr_t) tf->tf_a1,				(int) tf->tf_a2, &retval);		break;	case SYS_lseek:		pos = (((off_t)tf->tf_a2 << 32) | tf->tf_a3);		err = sys_lseek((userptr_t) tf->tf_a0, pos,				(userptr_t)(tf->tf_sp+16), &new_pos);		if (err == 0)		{			retval = (int32_t)(new_pos >> 32);			tf->tf_v1 = (int32_t)(new_pos & 0xFFFFFFFF);		}		break;	case SYS_close:		err = sys_close((userptr_t) tf->tf_a0, &retval);		break;	case SYS_dup2:		err = sys_dup2((userptr_t) tf->tf_a0, (userptr_t) tf->tf_a1, &retval);		break;	case SYS_getpid:		err = sys_getpid(&retval);		break;	case SYS_sbrk:		err = sys_sbrk((userptr_t)tf->tf_a0, &retval);		break;	case SYS_fork:		err = sys_fork(tf, &retval);		break;	case SYS_execv:		err = sys_execv((userptr_t) tf->tf_a0, (userptr_t) tf->tf_a1, &retval);		retval = 0;		break;	case SYS_waitpid:		err = sys_waitpid((userptr_t) tf->tf_a0, (userptr_t) tf->tf_a1,				(userptr_t) tf->tf_a2, &retval);		break;	case SYS__exit:		//kprintf("TEMPPPP:Exit has been called!	/n");		err = sys__exit((int) tf->tf_a0);		break;		/* Add stuff here */	default:		kprintf("Unknown syscall %d/n", callno);		err = ENOSYS;		break;	}
开发者ID:barrylanceleo,项目名称:Operating-system-abstractions-in-OS161,代码行数:101,


示例25: main

/* lock a byte range in a open file */int main(int argc, char *argv[]){	struct flock lock;	int fd, ret, status=1;	pid_t pid;	char *testdir = NULL;	testdir = getenv("TESTDIR");	if (testdir) chdir(testdir);	alarm(10);	if (!(pid=fork())) {		sleep(2);		fd = open(DATA, O_RDONLY);		if (fd == -1) {			fprintf(stderr,"ERROR: failed to open %s (errno=%d)/n", 				DATA, (int)errno);			exit(1);		}		lock.l_type = F_WRLCK;		lock.l_whence = SEEK_SET;		lock.l_start = 0x100000000LL;		lock.l_len = 4;		lock.l_pid = getpid();				lock.l_type = F_WRLCK;				/* check if a lock applies */		ret = fcntl(fd,F_GETLK,&lock);		if ((ret == -1) ||		    (lock.l_type == F_UNLCK)) {			fprintf(stderr,"ERROR: lock test failed (ret=%d errno=%d)/n", ret, (int)errno);			exit(1);		} else {			exit(0);		}	}	unlink(DATA);	fd = open(DATA, O_RDWR|O_CREAT|O_EXCL, 0600);	if (fd == -1) {		fprintf(stderr,"ERROR: failed to open %s (errno=%d)/n", 			DATA, (int)errno);		exit(1);	}	lock.l_type = F_WRLCK;	lock.l_whence = SEEK_SET;	lock.l_start = 0;	lock.l_len = 0x100000004LL;	lock.l_pid = getpid();	/* set a 100000004 byte write lock, should conflict with the above */	ret = fcntl(fd,F_SETLK,&lock);	sys_waitpid(pid, &status, 0);	unlink(DATA);	if (ret != 0) {		fprintf(stderr,"ERROR: failed to lock %s (errno=%d)/n", 			DATA, (int)errno);		exit(1);	}	if (lock.l_len < 0x100000004LL) {		fprintf(stderr,"ERROR: settign lock overflowed/n");		exit(1);	}#if defined(WIFEXITED) && defined(WEXITSTATUS)    if(WIFEXITED(status)) {        status = WEXITSTATUS(status);    } else {        status = 1;    }#else /* defined(WIFEXITED) && defined(WEXITSTATUS) */	status = (status == 0) ? 0 : 1;#endif /* defined(WIFEXITED) && defined(WEXITSTATUS) */	if (status) {		fprintf(stderr,"ERROR: lock test failed with status=%d/n", 			status);	}	exit(status);}
开发者ID:AIdrifter,项目名称:samba,代码行数:93,


示例26: chat_with_program

static BOOL chat_with_program(char *passwordprogram,char *name,char *chatsequence, BOOL as_root){  char *slavedev;  int master;  pid_t pid, wpid;  int wstat;  BOOL chstat = False;      /* allocate a pseudo-terminal device */  if ((master = findpty (&slavedev)) < 0) {    DEBUG(3,("Cannot Allocate pty for password change: %s/n",name));    return(False);  }  /*   * We need to temporarily stop CatchChild from eating   * SIGCLD signals as it also eats the exit status code. JRA.   */  CatchChildLeaveStatus();#ifdef __uClinux__  /* Hmmm, need to check this one further... */  DEBUG(0,("%s(%d): vfork()ing/n",__FILE__,__LINE__));  if ((pid = vfork()) < 0) {#else  if ((pid = fork()) < 0) {#endif    DEBUG(3,("Cannot fork() child for password change: %s/n",name));    close(master);    CatchChild();    return(False);  }  /* we now have a pty */  if (pid > 0){			/* This is the parent process */    if ((chstat = talktochild(master, chatsequence)) == False) {      DEBUG(3,("Child failed to change password: %s/n",name));      kill(pid, SIGKILL); /* be sure to end this process */    }	while((wpid = sys_waitpid(pid, &wstat, 0)) < 0) {      if(errno == EINTR) {        errno = 0;        continue;      }	  break;    }    if (wpid < 0) {      DEBUG(3,("The process is no longer waiting!/n/n"));      close(master);      CatchChild();      return(False);    }    /*     * Go back to ignoring children.     */    CatchChild();    close(master);    if (pid != wpid) {      DEBUG(3,("We were waiting for the wrong process ID/n"));	      return(False);    }    if (WIFEXITED(wstat) == 0) {      DEBUG(3,("The process exited while we were waiting/n"));      return(False);    }    if (WEXITSTATUS(wstat) != 0) {      DEBUG(3,("The status of the process exiting was %d/n", wstat));      return(False);    }      } else {    /* CHILD */    /*     * Lose any oplock capabilities.     */    set_process_capability(KERNEL_OPLOCK_CAPABILITY, False);    set_inherited_process_capability(KERNEL_OPLOCK_CAPABILITY, False);    /* make sure it doesn't freeze */    alarm(20);    if (as_root)      become_root(False);    DEBUG(3,("Dochild for user %s (uid=%d,gid=%d)/n",name,(int)getuid(),(int)getgid()));    chstat = dochild(master, slavedev, name, passwordprogram, as_root);	/*	 * The child should never return from dochild() ....	 */	DEBUG(0,("chat_with_program: Error: dochild() returned %d/n", chstat ));	exit(1);  }//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:wl530g-svn,代码行数:101,


示例27: syscall

//.........这里部分代码省略.........	 * Initialize retval to 0. Many of the system calls don't	 * really return a value, just 0 for success and -1 on	 * error. Since retval is the value returned on success,	 * initialize it to 0 by default; thus it's not necessary to	 * deal with it except for calls that return other values, 	 * like write.	 */	retval = 0;	switch (callno) {	    case SYS_reboot:		    err = sys_reboot(tf->tf_a0);		    break;	    case SYS___time:		    err = sys___time((userptr_t)tf->tf_a0,				     (userptr_t)tf->tf_a1);		    break;            /* ASST2: These implementations of read and write only work for             * console I/O (stdin, stdout and stderr file descriptors)             */            case SYS_read:                err = sys_read(tf->tf_a0, (userptr_t)tf->tf_a1, tf->tf_a2,                               &retval);                break;            case SYS_write:                err = sys_write(tf->tf_a0, (userptr_t)tf->tf_a1, tf->tf_a2,                                &retval);                break;            /* process calls */            case SYS__exit:            	thread_exit(_MKWAIT_EXIT(tf->tf_a0));            	panic("Returning from exit/n");	            case SYS_fork:            	err = sys_fork(tf, &retval);            	break;            /* ASST2 - You need to fill in the code for each of these cases */            case SYS_getpid:            	err = sys_getpid(&retval);                break;            case SYS_waitpid:                if(sys_waitpid(tf->tf_a0, /                		(userptr_t)tf->tf_a1, tf->tf_a2, &retval) == -1)                {                  err=retval;                }                else{                err=0;                }                break;            case SYS_kill:            	err = sys_kill(tf->tf_a0, tf->tf_a1);            	break;	    /* Even more system calls will go here */ 	    default:		kprintf("Unknown syscall %d/n", callno);		err = ENOSYS;		break;	}	if (err) {		/*		 * Return the error code. This gets converted at		 * userlevel to a return value of -1 and the error		 * code in errno.		 */		tf->tf_v0 = err;		tf->tf_a3 = 1;      /* signal an error */	}	else {		/* Success. */		tf->tf_v0 = retval;		tf->tf_a3 = 0;      /* signal no error */	}		/*	 * Now, advance the program counter, to avoid restarting	 * the syscall over and over again.	 */		tf->tf_epc += 4;	/* Make sure the syscall code didn't forget to lower spl */	KASSERT(curthread->t_curspl == 0);	/* ...or leak any spinlocks */	KASSERT(curthread->t_iplhigh_count == 0);}
开发者ID:SamuelChien,项目名称:OS161-ThreadMonitor,代码行数:101,



注:本文中的sys_waitpid函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ sys_write函数代码示例
C++ sys_timeout函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。