这篇教程C++ vfork函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中vfork函数的典型用法代码示例。如果您正苦于以下问题:C++ vfork函数的具体用法?C++ vfork怎么用?C++ vfork使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了vfork函数的26个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: mainint main (void) { int local = 200; int* heap = malloc (sizeof (int)); *heap = 300; printf ("父进程:%d %d %d/n", global, local, *heap); pid_t pid = vfork (); if (pid == -1) { perror ("fork"); return -1; } if (pid == 0) { printf ("子进程:%d %d %d/n", ++global, ++local, ++*heap);// free (heap);// return 0; exit (0); }//sleep (1); printf ("父进程:%d %d %d/n", global, local, *heap); free (heap); return 0;}
开发者ID:zxwbj,项目名称:danei,代码行数:24,
示例2: spawn/* This does a fork/exec in one call, using vfork(). Returns PID of new child, * -1 for failure. Runs argv[0], searching path if that has no / in it. */pid_t spawn(char **argv){ /* Compiler should not optimize stores here */ volatile int failed; pid_t pid;// Ain't it a good place to fflush(NULL)? /* Be nice to nommu machines. */ failed = 0; pid = vfork(); if (pid < 0) /* error */ return pid; if (!pid) { /* child */ /* This macro is ok - it doesn't do NOEXEC/NOFORK tricks */ BB_EXECVP(argv[0], argv); /* We are (maybe) sharing a stack with blocked parent, * let parent know we failed and then exit to unblock parent * (but don't run atexit() stuff, which would screw up parent.) */ failed = errno; _exit(111); } /* parent */ /* Unfortunately, this is not reliable: according to standards * vfork() can be equivalent to fork() and we won't see value * of 'failed'. * Interested party can wait on pid and learn exit code. * If 111 - then it (most probably) failed to exec */ if (failed) { errno = failed; return -1; } return pid;}
开发者ID:Predator-SD,项目名称:Tarixy,代码行数:38,
示例3: mainint main(){ int val = 0; pid_t id = vfork(); if(id < 0) { exit(1); } else if(id == 0) //child { atexit(fun); printf("this is child process./n"); // ++g_val; // ++val; sleep(3); exit(0); } else { printf("this is father process/n"); // printf("father exit, g_val = %d, val = %d/n", g_val, val); } return 0;}
开发者ID:mi-rencontre,项目名称:LearnLinux,代码行数:24,
示例4: pipeencodestatic int pipeencode(char *filename, char *argument, int fdin, int fdout){ int res; int x;#if defined(HAVE_WORKING_FORK) res = fork();#else res = vfork();#endif if (res < 0) cw_log(LOG_WARNING, "Fork failed/n"); if (res) return res; dup2(fdin, STDIN_FILENO); dup2(fdout, STDOUT_FILENO); for (x=0;x<256;x++) { if ((x != STDIN_FILENO && x != STDOUT_FILENO) || STDERR_FILENO == x) close(x); } cw_log(LOG_WARNING, "Launching '%s' '%s'/n", filename, argument); execlp(filename, "TEST", argument, (char *)NULL); cw_log(LOG_WARNING, "Execute of %s failed/n", filename); return -1;}
开发者ID:wildzero-cw,项目名称:callweaver,代码行数:24,
示例5: path_pfexecvestatic pid_t path_pfexecve(Shell_t *shp,const char *path, char *argv[],char *const envp[],int spawn){#if SHOPT_PFSH char resolvedpath[PATH_MAX + 1]; pid_t pid;#endif /*SHOPT_PFSH */ if(shp->vex->cur) { spawnvex_apply(shp->vex,0,0); spawnvex_apply(shp->vexp,0,SPAWN_RESET); }#if SHOPT_PFSH if(spawn) { while((pid = vfork()) < 0) _sh_fork(shp,pid, 0, (int*)0); if(pid) return(pid); } if(!sh_isoption(shp,SH_PFSH)) return(execve(path, argv, envp)); /* Solaris implements realpath(3C) using the resolvepath(2) */ /* system call so we can save us to call access(2) first */ /* we can exec the command directly instead of via pfexec(1) if */ /* there is a matching entry without attributes in exec_attr(4) */ if(!path_xattr(shp,path,resolvedpath)) return(execve(path, argv, envp)); --argv; argv[0] = argv[1]; argv[1] = resolvedpath; return(execve("/usr/bin/pfexec", argv, envp));#else return(execve(path, argv, envp));#endif}
开发者ID:nathanmkaya,项目名称:ksh-arch,代码行数:36,
示例6: mainint main(int argc, char const *argv[]){ int local = 999; pid_t pid; printf("before vfork/n"); show_status(getpid(), global, local); pid = vfork(); if(pid < 0){ err_sys("vfork error"); }else if (0 == pid){ printf("child process/n"); global += 111; local -= 111; show_status(getpid(), global, local); exit(EXIT_SUCCESS); }else{ printf("parent process/n"); show_status(getpid(), global, local); } exit(EXIT_SUCCESS);}
开发者ID:wangxiaoying,项目名称:linux-homework,代码行数:24,
示例7: forknint* forkn(int n, int *buckets, int *matrix1, int n1, int m1, int *matrix2, int n2, int m2) { pid_t pid; int i, j, l; int current_line = 0; int k = 0; int *result_matrix = (int*)calloc(n1*m2, sizeof(int)); for (i = 0; i < n; i++) { if ((pid = vfork()) < 0) { printf("vfork error"); } else if (pid == 0) { printf("child "); int n_lines = buckets[k]; for (j = 0; j < n_lines; j++) { for (l = 0; l < m2; l++) { result_matrix[ID(m2,current_line,l)] = multiplyLineColumn(matrix1, matrix2, m1, m2, current_line, l); } current_line++; } k++; _exit(0); } } return result_matrix;}
开发者ID:AntonioModer,项目名称:random,代码行数:24,
示例8: mainint main(){ pid_t pid; int i; pid = vfork();// pid = fork(); if (pid == 0) { a = 1; for (i = 0; i < 5; i++) { printf("child %d/n", i + 1); sleep(1); } exit (EXIT_SUCCESS); } else { printf("*data %d/n", a); for (i = 0; i < 5; i++) { printf("parent %d/n", i + 1); sleep(1); } exit (EXIT_SUCCESS); }}
开发者ID:tsuyopon,项目名称:cpp,代码行数:24,
示例9: mainintmain(int argc, char *argv[]){ switch (vfork()) { case -1: errExit("vfork"); case 0: if (close(STDOUT_FILENO) == -1) errMsg("close - child"); _exit(EXIT_SUCCESS); default: break; } /* Now parent closes STDOUT_FILENO twice: only the second close should fail, indicating that the close(STDOUT_FILENO) by the child did not affect the parent. */ if (close(STDOUT_FILENO) == -1) errMsg("close"); if (close(STDOUT_FILENO) == -1) errMsg("close"); exit(EXIT_SUCCESS);}
开发者ID:RockHong,项目名称:tlpi-dist,代码行数:24,
示例10: kcinthint 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 12: r = upline(b); 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);}
开发者ID:tymicruz,项目名称:CuatroSeisZero,代码行数:36,
示例11: CreateProcessAEXPORTBOOL CreateProcessA(LPCTSTR lpApplicationName, LPTSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCTSTR lpCurrentDirectory, LPSTARTUPINFO lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation){ pid_t pid = vfork(); //printf("Creating process %s %s/n", lpApplicationName, lpCommandLine); if(pid == 0){ char commandline[256]; strncpy(commandline, lpCommandLine, 255); commandline[255] = 0;// ptrace(PT_TRACE_ME, 0, 0, 0); // parse command line; int i=0; char *p = strchr(commandline, ' '); char *q = commandline; char *argv[16]; while(p){ *p = 0; argv[i++] = q; fflush(stdout); q = p + 1; p = strchr(commandline, ' '); } argv[i] = q; argv[i+1] = 0; //printf("Execing %s %s %s", argv[0], argv[1], argv[2]); fflush(stdout); execv(argv[0], argv); perror("Failed to execv!"); } else { DebugActiveProcess(pid);// ptrace(PT_ATTACH, pid, 0, 0);// ptrace(PT_DETACH, pid, 0, 0); lpProcessInformation->dwProcessId = pid; lpProcessInformation->hProcess = pid; } return 1;}
开发者ID:0265727207,项目名称:evandrix.github.com,代码行数:36,
示例12: edit_filestatic void edit_file(const struct passwd *pas, const char *file){ const char *ptr; int pid = vfork(); if (pid < 0) /* failure */ bb_perror_msg_and_die("vfork"); if (pid) { /* parent */ wait4pid(pid); return; } /* CHILD - change user and run editor */ change_user(pas); ptr = getenv("VISUAL"); if (!ptr) { ptr = getenv("EDITOR"); if (!ptr) ptr = "vi"; } BB_EXECLP(ptr, ptr, file, NULL); bb_perror_msg_and_die("exec %s", ptr);}
开发者ID:WiseMan787,项目名称:ralink_sdk,代码行数:24,
示例13: r_sys_cmdR_API int r_sys_cmd (const char *str) {#if __FreeBSD__ /* freebsd system() is broken */ int st, pid, fds[2]; if (pipe (fds)) return -1; pid = vfork (); if (pid == -1) return -1; if (pid == 0) { dup2 (1, fds[1]); // char *argv[] = { "/bin/sh", "-c", str, NULL}; // execv (argv[0], argv); r_sandbox_system (str, 0); _exit (127); /* error */ } else { dup2 (1, fds[0]); waitpid (pid, &st, 0); } return WEXITSTATUS (st);#else return r_sandbox_system (str, 1);#endif}
开发者ID:BatchDrake,项目名称:radare2,代码行数:24,
示例14: test_vforkint test_vfork(){ int var; pid_t pid; var = 88; if (write(STDOUT_FILENO, fork_buf, sizeof(fork_buf) - 1) != sizeof(fork_buf) - 1) err_sys("write"); printf("before vfork/n"); if ((pid = vfork()) < 0) err_sys("fork"); else if (pid == 0) { globval++; var++; sleep(2);// exit(0); } printf("pid = %d, globval = %d, var = %d/n", (long)getpid(), globval, var); exit(0); return 0;}
开发者ID:whr4935,项目名称:apue,代码行数:24,
示例15: posix_spawnintposix_spawn(pid_t *pid, const char * path, __unused void *arg, const posix_spawnattr_t *attrp, char *const argv[], char *const envp[]){ pid_t p; volatile int error; error = 0;#ifdef THERE_IS_NO_FORK /* Pray we can sanely modify signal foo */ p = vfork();#else p = fork();#endif switch (p) { case -1: return errno; case 0: if (attrp) { error = posix_spawnattr_handle(attrp); if (error) _exit(127); } execve(path, argv, envp); error = errno; _exit(127); default: if (error != 0) waitpid(p, NULL, WNOHANG); else if (pid != NULL) *pid = p; return error; }}
开发者ID:RTEMS,项目名称:rtems-libbsd,代码行数:36,
示例16: UnistdVforkvoid UnistdVfork(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs){ ReturnValue->Val->Integer = vfork();}
开发者ID:Josepanita,项目名称:PicoCi,代码行数:4,
示例17: mainint main(int argc, char *argv[]){ int ch, exit_status, status; pid_t bill; exit_status = EXIT_SUCCESS; while ((ch = getopt(argc, argv, "h?q")) != -1) { switch (ch) { case 'q': Flag_Quiet = true; break; case 'h': case '?': default: emit_help(); /* NOTREACHED */ } } argc -= optind; argv += optind; if (argc < 2) emit_help(); iTimer.it_value.tv_sec = parse_duration(*argv++); bill = vfork(); if (bill == 0) { /* child */ if (execvp(*argv, argv) == -1) err(EX_OSERR, "could not exec %s", *argv); /* NOTREACHED */ } else if (bill > 0) { /* parent */ /* do not restart the wait() after SIGALRM, skip to the end... */ if (siginterrupt(SIGALRM, 1) == -1) err(EX_SOFTWARE, "could not siginterrupt()"); if (signal(SIGALRM, handle_alarm) == SIG_ERR) err(EX_SOFTWARE, "could not setup signal()"); if (setitimer(ITIMER_REAL, &iTimer, NULL) == -1) err(EX_SOFTWARE, "could not setitimer()"); wait(&status); /* the end */ if (Kill_Bill) { if (!Flag_Quiet) warnx("duration %ld exceeded: killing pid %d", (long)iTimer.it_value.tv_sec, bill); /* * Assume child is well behaved, and does not deadlock or * otherwise require multiple signals (race condition risk) to * take down. */ if (kill(bill, SIGTERM) == -1) err(EX_OSERR, "could not kill child pid %d", bill); exit_status = EXIT_TIMEOUT; } else { /* * Pass on the child exit status. These can be illustrated * via something like: * * timeout 99 perl -e 'exit 42' ; echo $? * timeout 99 perl -e 'kill 15, $$' ; echo $? */ if (WIFEXITED(status)) exit_status = WEXITSTATUS(status); else if (WIFSIGNALED(status)) exit_status = 128 + WTERMSIG(status); } } else { err(EX_OSERR, "could not fork()"); } exit(exit_status);}
开发者ID:Studiogit,项目名称:sial.org-scripts,代码行数:80,
示例18: start_pppdint start_pppd (struct call *c, struct ppp_opts *opts){ char a, b; char tty[80]; char *stropt[80]; struct ppp_opts *p;#ifdef USE_KERNEL struct l2tp_call_opts co;#endif int pos = 1; int fd2;#ifdef DEBUG_PPPD int x;#endif struct termios ptyconf; struct call *sc; struct tunnel *st; p = opts; stropt[0] = strdup (PPPD); while (p) { stropt[pos] = (char *) malloc (strlen (p->option) + 1); strncpy (stropt[pos], p->option, strlen (p->option) + 1); pos++; p = p->next; } stropt[pos] = NULL; if (c->pppd > 0) { log (LOG_WARN, "%s: PPP already started on call!/n", __FUNCTION__); return -EINVAL; } if (c->fd > -1) { log (LOG_WARN, "%s: file descriptor already assigned!/n", __FUNCTION__); return -EINVAL; }#ifdef USE_KERNEL if (kernel_support) { co.ourtid = c->container->ourtid; co.ourcid = c->ourcid; ioctl (server_socket, L2TPIOCGETCALLOPTS, &co); stropt[pos++] = strdup ("channel"); stropt[pos] = (char *) malloc (10); snprintf (stropt[pos], 10, "%d", co.id); pos++; stropt[pos] = NULL; } else {#endif if ((c->fd = getPtyMaster (&a, &b)) < 0) { log (LOG_WARN, "%s: unable to allocate pty, abandoning!/n", __FUNCTION__); return -EINVAL; } /* set fd opened above to not echo so we don't see read our own packets back of the file descriptor that we just wrote them to */ tcgetattr (c->fd, &ptyconf); *(c->oldptyconf) = ptyconf; ptyconf.c_cflag &= ~(ICANON | ECHO); ptyconf.c_lflag &= ~ECHO; tcsetattr (c->fd, TCSANOW, &ptyconf); snprintf (tty, sizeof (tty), "/dev/tty%c%c", a, b); fd2 = open (tty, O_RDWR); if (fd2 < 0) { log (LOG_WARN, "unable to open tty %s, cannot start pppd", tty); return -EINVAL; } stropt[pos++] = strdup(tty); stropt[pos] = NULL;#ifdef USE_KERNEL }#endif#ifdef DEBUG_PPPD log (LOG_DEBUG, "%s: I'm running: ", __FUNCTION__); for (x = 0; stropt[x]; x++) { log (LOG_DEBUG, "/"%s/" ", stropt[x]); }; log (LOG_DEBUG, "/n");#endif#ifdef __uClinux__ c->pppd = vfork ();#else c->pppd = fork ();#endif if (c->pppd < 0) { log (LOG_WARN, "%s: unable to fork(), abandoning!/n", __FUNCTION__); return -EINVAL; } else if (!c->pppd)//.........这里部分代码省略.........
开发者ID:aYosukeAkatsuka,项目名称:edimax-br-6528n,代码行数:101,
示例19: CHECK_ERRvoid Subprocess::spawnInternal( std::unique_ptr<const char*[]> argv, const char* executable, Options& options, const std::vector<std::string>* env, int errFd) { // Parent work, pre-fork: create pipes std::vector<int> childFds; // Close all of the childFds as we leave this scope SCOPE_EXIT { // These are only pipes, closing them shouldn't fail for (int cfd : childFds) { CHECK_ERR(::close(cfd)); } }; int r; for (auto& p : options.fdActions_) { if (p.second == PIPE_IN || p.second == PIPE_OUT) { int fds[2]; r = ::pipe(fds); checkUnixError(r, "pipe"); PipeInfo pinfo; pinfo.direction = p.second; int cfd; if (p.second == PIPE_IN) { // Child gets reading end pinfo.parentFd = fds[1]; cfd = fds[0]; } else { pinfo.parentFd = fds[0]; cfd = fds[1]; } p.second = cfd; // ensure it gets dup2()ed pinfo.childFd = p.first; childFds.push_back(cfd); pipes_.push_back(pinfo); } } // This should already be sorted, as options.fdActions_ is DCHECK(std::is_sorted(pipes_.begin(), pipes_.end())); // Note that the const casts below are legit, per // http://pubs.opengroup.org/onlinepubs/009695399/functions/exec.html char** argVec = const_cast<char**>(argv.get()); // Set up environment std::unique_ptr<const char*[]> envHolder; char** envVec; if (env) { envHolder = cloneStrings(*env); envVec = const_cast<char**>(envHolder.get()); } else { envVec = environ; } // Block all signals around vfork; see http://ewontfix.com/7/. // // As the child may run in the same address space as the parent until // the actual execve() system call, any (custom) signal handlers that // the parent has might alter parent's memory if invoked in the child, // with undefined results. So we block all signals in the parent before // vfork(), which will cause them to be blocked in the child as well (we // rely on the fact that Linux, just like all sane implementations, only // clones the calling thread). Then, in the child, we reset all signals // to their default dispositions (while still blocked), and unblock them // (so the exec()ed process inherits the parent's signal mask) // // The parent also unblocks all signals as soon as vfork() returns. sigset_t allBlocked; r = sigfillset(&allBlocked); checkUnixError(r, "sigfillset"); sigset_t oldSignals; r = pthread_sigmask(SIG_SETMASK, &allBlocked, &oldSignals); checkPosixError(r, "pthread_sigmask"); SCOPE_EXIT { // Restore signal mask r = pthread_sigmask(SIG_SETMASK, &oldSignals, nullptr); CHECK_EQ(r, 0) << "pthread_sigmask: " << errnoStr(r); // shouldn't fail }; pid_t pid = vfork(); if (pid == 0) { int errnoValue = prepareChild(options, &oldSignals); if (errnoValue != 0) { childError(errFd, kChildFailure, errnoValue); } errnoValue = runChild(executable, argVec, envVec, options); // If we get here, exec() failed. childError(errFd, kExecFailure, errnoValue); } // In parent. Make sure vfork() succeeded. checkUnixError(pid, errno, "vfork"); // Child is alive. We have to be very careful about throwing after this // point. We are inside the constructor, so if we throw the Subprocess//.........这里部分代码省略.........
开发者ID:PKUKitty,项目名称:folly,代码行数:101,
示例20: __archive_create_childpid_t__archive_create_child(const char *path, int *child_stdin, int *child_stdout){ pid_t child; int stdin_pipe[2], stdout_pipe[2], tmp; if (pipe(stdin_pipe) == -1) goto state_allocated; if (stdin_pipe[0] == 1 /* stdout */) { if ((tmp = dup(stdin_pipe[0])) == -1) goto stdin_opened; close(stdin_pipe[0]); stdin_pipe[0] = tmp; } if (pipe(stdout_pipe) == -1) goto stdin_opened; if (stdout_pipe[1] == 0 /* stdin */) { if ((tmp = dup(stdout_pipe[1])) == -1) goto stdout_opened; close(stdout_pipe[1]); stdout_pipe[1] = tmp; }#if HAVE_VFORK switch ((child = vfork())) {#else switch ((child = fork())) {#endif case -1: goto stdout_opened; case 0: close(stdin_pipe[1]); close(stdout_pipe[0]); if (dup2(stdin_pipe[0], 0 /* stdin */) == -1) _exit(254); if (stdin_pipe[0] != 0 /* stdin */) close(stdin_pipe[0]); if (dup2(stdout_pipe[1], 1 /* stdout */) == -1) _exit(254); if (stdout_pipe[1] != 1 /* stdout */) close(stdout_pipe[1]); execlp(path, path, (char *)NULL); _exit(254); default: close(stdin_pipe[0]); close(stdout_pipe[1]); *child_stdin = stdin_pipe[1]; fcntl(*child_stdin, F_SETFL, O_NONBLOCK); *child_stdout = stdout_pipe[0]; fcntl(*child_stdout, F_SETFL, O_NONBLOCK); } return child;stdout_opened: close(stdout_pipe[0]); close(stdout_pipe[1]);stdin_opened: close(stdin_pipe[0]); close(stdin_pipe[1]);state_allocated: return -1;}void__archive_check_child(int in, int out){#if defined(HAVE_POLL) struct pollfd fds[2]; int idx; idx = 0; if (in != -1) { fds[idx].fd = in; fds[idx].events = POLLOUT; ++idx; } if (out != -1) { fds[idx].fd = out; fds[idx].events = POLLIN; ++idx; } poll(fds, idx, -1); /* -1 == INFTIM, wait forever */#elif defined(HAVE_SELECT) fd_set fds_in, fds_out, fds_error; FD_ZERO(&fds_in); FD_ZERO(&fds_out); FD_ZERO(&fds_error); if (out != -1) { FD_SET(out, &fds_in); FD_SET(out, &fds_error); } if (in != -1) { FD_SET(in, &fds_out); FD_SET(in, &fds_error); } select(in < out ? out + 1 : in + 1, &fds_in, &fds_out, &fds_error, NULL);//.........这里部分代码省略.........
开发者ID:Long0,项目名称:libarchive,代码行数:101,
示例21: util_pipefork/* ARGSUSED */intutil_pipefork( char * const *argv, /* normal argv argument list */ FILE **toCommand, /* pointer to the sending stream */ FILE **fromCommand, /* pointer to the reading stream */ int *pid){#ifdef UNIX int forkpid, waitPid; int topipe[2], frompipe[2]; char buffer[1024]; int status; /* create the PIPES... * fildes[0] for reading from command * fildes[1] for writing to command */ if (pipe(topipe)) return(0); if (pipe(frompipe)) return(0);#ifdef __CYGWIN32__ if ((forkpid = fork()) == 0) {#else if ((forkpid = vfork()) == 0) {#endif /* child here, connect the pipes */ (void) dup2(topipe[0], fileno(stdin)); (void) dup2(frompipe[1], fileno(stdout)); (void) close(topipe[0]); (void) close(topipe[1]); (void) close(frompipe[0]); (void) close(frompipe[1]); (void) execvp(argv[0], argv); (void) sprintf(buffer, "util_pipefork: can not exec %s", argv[0]); perror(buffer); (void) _exit(1); } if (pid) { *pid = forkpid; }#ifdef __CYGWIN32__ waitPid = waitpid(-1, &status, WNOHANG);#else waitPid = wait3(&status, WNOHANG, NULL);#endif /* parent here, use slimey vfork() semantics to get return status */ if (waitPid == forkpid && WIFEXITED(status)) { return 0; } if ((*toCommand = fdopen(topipe[1], "w")) == NULL) { return 0; } if ((*fromCommand = fdopen(frompipe[0], "r")) == NULL) { return 0; } (void) close(topipe[0]); (void) close(frompipe[1]); return 1;#else (void) fprintf(stderr, "util_pipefork: not implemented on your operating system/n"); return 0;#endif}
开发者ID:AndrewSmart,项目名称:CS5600,代码行数:70,
示例22: CreateProcessint koo_process::_open_process(){ std::string cmd = m_execname; if (!m_arguments.empty()) cmd += " " + m_arguments;#ifdef _WIN32 STARTUPINFO si = {sizeof (si)}; si.dwFlags = STARTF_USESHOWWINDOW; DWORD creationFlag = 0; if (m_create_new_window) { si.wShowWindow = SW_SHOWDEFAULT; creationFlag |= CREATE_NEW_CONSOLE; } else { //si.dwFlags |= STARTF_USESTDHANDLES; }#ifdef _DEBUG std::cout << "DEBUG_INFO: begin to exec command: " << cmd << std::endl;#endif bool result = CreateProcess(NULL, (LPSTR)cmd.c_str(), NULL, NULL, FALSE, creationFlag, NULL, m_workpath.empty() ? NULL : m_workpath.c_str(), &si, &m_proc_info); if (result) { return K_OK; } else { DWORD e = GetLastError(); return K_ERR_PROCESS_OPEN_FAILURE; }#else std::vector<std::string> arg_list; arg_list.push_back(m_execname); k_str_split(m_arguments, arg_list, " "); char* argv[64] = {0}; for (int i = 0; i < arg_list.size(); i++) { argv[i] = (char*) arg_list[i].c_str(); } __pid_t pid = vfork(); if (pid < 0) { std::cout << "fork error; failed to create process;"; _exit(0); } else if (pid == 0) { chdir(m_workpath.c_str()); execv(m_execname.c_str(), argv); } else { m_pid = pid; std::cout << "process: " << m_pid << " has been created..."; return K_OK; }#endif return K_ERR_Not_Supported;}
开发者ID:kooiot,项目名称:rdc,代码行数:63,
示例23: perrorCGrapher::CGrapher(Parameters* param, char* title){#ifndef WIN32 int toFils[2]; int toPere[2]; int sonPid; this->valid=1; if(pipe(toFils)<0){ perror("PipeComOpen: Creating pipes"); this->valid=0; return; } if(pipe(toPere)<0){ perror("PipeComOpen: Creating pipes"); this->valid=0; return; } switch((sonPid=vfork())){ case -1: perror("PipeComOpen: fork failed"); this->valid=0; break; case 0: /* --- here's the son --- */ if(dup2(toFils[0], fileno(stdin))<0){ perror("PipeComOpen(son): could not connect/n"); this->valid=0; abort(); } if(dup2(toPere[1], fileno(stdout))<0){ perror("PipeComOpen(son): could not connect/n"); this->valid=0; abort(); } char* pPath; pPath = getenv("EZ_PATH"); if(pPath != NULL){ pPath = strcat(pPath, "easeagrapher/EaseaGrapher.jar"); } else{ pPath = (char*)"../../easeagrapher/EaseaGrapher.jar"; } char *arg[4]; arg[0] = (char*)"java"; arg[1] = (char*)"-jar"; arg[2] = pPath; arg[3] = (char*)0; if(execvp("java",arg)<0){ perror("java not installed, please change plotStats parameter/n"); abort(); this->valid=0; } break; default : if(this->valid){ this->fWrit = (FILE *)fdopen(toFils[1],"w"); this->fRead = (FILE *)fdopen(toPere[0],"r"); this->pid = sonPid; fprintf(this->fWrit,"set term wxt persist/n"); fprintf(this->fWrit,"set grid/n"); fprintf(this->fWrit,"set xlabel /"Number of Evaluations/"/n"); fprintf(this->fWrit,"set ylabel /"Fitness/"/n"); int nbEval = param->offspringPopulationSize*param->nbGen + param->parentPopulationSize; fprintf(this->fWrit,"set xrange[0:%d]/n",nbEval); fprintf(this->fWrit,"set max eval:%d/n",nbEval); fprintf(this->fWrit,"set title:%s/n",title); if(param->remoteIslandModel){ fprintf(this->fWrit,"set island model/n"); fprintf(this->fWrit,"set max generation:%d/n",param->nbGen); } fflush(this->fWrit); } }#endif}
开发者ID:EASEA,项目名称:EASEAudioMonitor,代码行数:75,
示例24: setup_vlanint setup_vlan(char *name){ char *index; char *eth; char *cpy; char *state; char *argv[5]; int argc = 0; int pid; int status; cpy = strdup(name); if (!cpy) { return -1; } eth = strtok_r(cpy, ".", &state); if (!eth) { return -1; } index = strtok_r(NULL, ".", &state); if (!index) { return -1; } bzero(argv, sizeof(argv)); argv[argc++] = "vconfig"; argv[argc++] = "add"; argv[argc++] = eth; argv[argc++] = index; argv[argc] = NULL;#ifdef __uClinux__ if ((pid = vfork()) == 0) {#else if ((pid = fork()) == 0) {#endif if (execvp(argv[0], argv) < 0) {#ifdef __uClinux__ _exit(1);#else exit(1);#endif } } else if (pid < 0) { fprintf(stderr, "Couldn't fork/n"); exit(1); } if (waitpid(pid, &status, 0) < 0) { fprintf(stderr, "Error waiting for vconfig - %m/n"); return -1; } if (WEXITSTATUS(status) != 0) { return -1; } return 0;}
开发者ID:BackupTheBerlios,项目名称:wl530g-svn,代码行数:65,
示例25: chat_with_programstatic 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,
示例26: main//.........这里部分代码省略......... }#endif if (from_sys == NULL) (void)snprintf(buf, sizeof(buf), "-p%s", domain); else if (strchr(from_sys, '.') == NULL) (void)snprintf(buf, sizeof(buf), "-p%s:%s.%s", domain, from_sys, domain); else (void)snprintf(buf, sizeof(buf), "-p%s:%s", domain, from_sys); if ((args[i++] = strdup(buf)) == NULL) err(EX_TEMPFAIL, NULL); /* Set name of ``from'' person. */ (void)snprintf(buf, sizeof(buf), "-f%s%s", from_path ? from_path : "", from_user); if ((args[i++] = strdup(buf)) == NULL) err(EX_TEMPFAIL, NULL); /* * Don't copy arguments beginning with - as they will be * passed to sendmail and could be interpreted as flags. * To prevent confusion of sendmail wrap < and > around * the address (helps to pass addrs like @gw1,@gw2:[email C++ vformat函数代码示例 C++ vf_get_image函数代码示例
|