这篇教程C++ wait_for_pid函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中wait_for_pid函数的典型用法代码示例。如果您正苦于以下问题:C++ wait_for_pid函数的具体用法?C++ wait_for_pid怎么用?C++ wait_for_pid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了wait_for_pid函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: cgm_createbool cgm_create(const char *controller, const char *cg, uid_t uid, gid_t gid){ int32_t e; pid_t pid = fork(); if (pid) { if (wait_for_pid(pid) != 0) return false; return true; } if (setgroups(0, NULL)) _exit(1); if (setresgid(gid, gid, gid)) _exit(1); if (setresuid(uid, uid, uid)) _exit(1); if (!cgm_dbus_connect()) { _exit(1); } if ( cgmanager_create_sync(NULL, cgroup_manager, controller, cg, &e) != 0) { NihError *nerr; nerr = nih_error_get(); fprintf(stderr, "call to create failed (%s:%s): %s/n", controller, cg, nerr->message); nih_free(nerr); cgm_dbus_disconnect(); _exit(1); } cgm_dbus_disconnect(); _exit(0);}
开发者ID:RobinSystems,项目名称:lxcfs,代码行数:34,
示例2: killDbint killDb(int port, ProcessId _pid, int signal, const BSONObj& opt) { ProcessId pid; if (port > 0) { if (!registry.isPortRegistered(port)) { log() << "No db started on port: " << port; return 0; } pid = registry.pidForPort(port); } else { pid = _pid; } kill_wrapper(pid, signal, port, opt); int exitCode = EXIT_FAILURE; try { wait_for_pid(pid, true, &exitCode); } catch (...) { warning() << "process " << pid << " failed to terminate."; return EXIT_FAILURE; } if (signal == SIGKILL) { sleepmillis(4000); // allow operating system to reclaim resources } return exitCode;}
开发者ID:DINKIN,项目名称:mongo,代码行数:28,
示例3: child_statusvoid child_status(void) { /* dead libwrap or 'exec' process detected */ int pid, status;#ifdef HAVE_WAIT_FOR_PID while((pid=wait_for_pid(-1, &status, WNOHANG))>0) {#else if((pid=wait(&status))>0) {#endif#ifdef WIFSIGNALED if(WIFSIGNALED(status)) { s_log(LOG_INFO, "Child process %d terminated on signal %d", pid, WTERMSIG(status)); } else { s_log(LOG_INFO, "Child process %d finished with code %d", pid, WEXITSTATUS(status)); }#else s_log(LOG_INFO, "Child process %d finished with status %d", pid, status);#endif }}static void signal_handler(int sig) { int saved_errno; saved_errno=errno; signal_post(sig); signal(sig, signal_handler); errno=saved_errno;}
开发者ID:davean,项目名称:stunnel-xforwardfor,代码行数:31,
示例4: do_rsyncstatic int do_rsync(const char *src, const char *dest){ // call out to rsync pid_t pid; char *s; size_t l; pid = fork(); if (pid < 0) return -1; if (pid > 0) return wait_for_pid(pid); process_unlock(); // we're no longer sharing l = strlen(src) + 2; s = malloc(l); if (!s) exit(1); strcpy(s, src); s[l-2] = '/'; s[l-1] = '/0'; execlp("rsync", "rsync", "-a", s, dest, (char *)NULL); exit(1);}
开发者ID:klim-iv,项目名称:lxc,代码行数:25,
示例5: CheckProgramBSONObj CheckProgram(const BSONObj& args, void* data) { ProcessId pid = ProcessId::fromNative(singleArg(args).numberInt()); bool isDead = wait_for_pid(pid, false); if (isDead) registry.deleteProgram(pid); return BSON(string("") << (!isDead));}
开发者ID:stevelyall,项目名称:mongol-db,代码行数:7,
示例6: WaitProgram BSONObj WaitProgram( const BSONObj& a, void* data ) { ProcessId pid = ProcessId::fromNative(singleArg( a ).numberInt()); int exit_code = -123456; // sentinel value wait_for_pid( pid, true, &exit_code ); registry.deletePid( pid ); return BSON( string("") << exit_code); }
开发者ID:ambroff,项目名称:mongo,代码行数:7,
示例7: client_statusNOEXPORT void client_status(void) { /* dead children detected */ int pid, status; char *sig_name;#ifdef HAVE_WAIT_FOR_PID while((pid=wait_for_pid(-1, &status, WNOHANG))>0) {#else if((pid=wait(&status))>0) {#endif#ifdef WIFSIGNALED if(WIFSIGNALED(status)) { sig_name=signal_name(WTERMSIG(status)); s_log(LOG_DEBUG, "Process %d terminated on %s", pid, sig_name); str_free(sig_name); } else { s_log(LOG_DEBUG, "Process %d finished with code %d", pid, WEXITSTATUS(status)); } }#else s_log(LOG_DEBUG, "Process %d finished with code %d", pid, status); }#endif}
开发者ID:mkschreder,项目名称:stunnel,代码行数:26,
示例8: client_statusstatic void client_status(void) { /* dead children detected */ int pid, status;#ifdef HAVE_WAIT_FOR_PID while((pid=wait_for_pid(-1, &status, WNOHANG))>0) { --num_clients; /* one client less */#else if((pid=wait(&status))>0) { --num_clients; /* one client less */#endif#ifdef WIFSIGNALED if(WIFSIGNALED(status)) { s_log(LOG_DEBUG, "Process %d terminated on signal %d (%d left)", pid, WTERMSIG(status), num_clients); } else { s_log(LOG_DEBUG, "Process %d finished with code %d (%d left)", pid, WEXITSTATUS(status), num_clients); } }#else s_log(LOG_DEBUG, "Process %d finished with code %d (%d left)", pid, status, num_clients); }#endif}
开发者ID:djs55,项目名称:stunnel,代码行数:25,
示例9: do_lvm_create /* * path must be '/dev/$vg/$lv', $vg must be an existing VG, and $lv must not * yet exist. This function will attempt to create /dev/$vg/$lv of size * $size. If thinpool is specified, we'll check for it's existence and if * it's * a valid thin pool, and if so, we'll create the requested lv from that * thin * pool. */ static int do_lvm_create(const char *path, uint64_t size, const char *thinpool){ int ret, pid, len; char sz[24], *pathdup, *vg, *lv, *tp = NULL; if ((pid = fork()) < 0) { SYSERROR("failed fork"); return -1; } if (pid > 0) return wait_for_pid(pid); // specify bytes to lvcreate ret = snprintf(sz, 24, "%"PRIu64"b", size); if (ret < 0 || ret >= 24) exit(EXIT_FAILURE); pathdup = strdup(path); if (!pathdup) exit(EXIT_FAILURE); lv = strrchr(pathdup, '/'); if (!lv) exit(EXIT_FAILURE); *lv = '/0'; lv++; vg = strrchr(pathdup, '/'); if (!vg) exit(EXIT_FAILURE); vg++; if (thinpool) { len = strlen(pathdup) + strlen(thinpool) + 2; tp = alloca(len); ret = snprintf(tp, len, "%s/%s", pathdup, thinpool); if (ret < 0 || ret >= len) exit(EXIT_FAILURE); ret = lvm_is_thin_pool(tp); INFO("got %d for thin pool at path: %s", ret, tp); if (ret < 0) exit(EXIT_FAILURE); if (!ret) tp = NULL; } if (!tp) execlp("lvcreate", "lvcreate", "-L", sz, vg, "-n", lv, (char *)NULL); else execlp("lvcreate", "lvcreate", "--thinpool", tp, "-V", sz, vg, "-n", lv, (char *)NULL); SYSERROR("execlp"); exit(EXIT_FAILURE);}
开发者ID:4b42,项目名称:lxc,代码行数:68,
示例10: cgm_get/* cgm_get is called to get container cgroup settings, not during startup */static int cgm_get(const char *filename, char *value, size_t len, const char *name, const char *lxcpath){ pid_t pid; int p[2], ret, newlen, readlen; if (pipe(p) < 0) return -1; if ((pid = fork()) < 0) { close(p[0]); close(p[1]); return -1; } if (!pid) // do_cgm_get exits do_cgm_get(name, lxcpath, filename, p[1], len && value); close(p[1]); ret = read(p[0], &newlen, sizeof(newlen)); if (ret != sizeof(newlen)) { close(p[0]); ret = -1; goto out; } if (!len || !value) { close(p[0]); ret = newlen; goto out; } memset(value, 0, len); if (newlen < 0) { // child is reporting an error close(p[0]); ret = -1; goto out; } if (newlen == 0) { // empty read close(p[0]); ret = 0; goto out; } readlen = newlen > len ? len : newlen; ret = read(p[0], value, readlen); close(p[0]); if (ret != readlen) { ret = -1; goto out; } if (newlen >= len) { value[len-1] = '/0'; newlen = len-1; } else if (newlen+1 < len) { // cgmanager doesn't add eol to last entry value[newlen++] = '/n'; value[newlen] = '/0'; } ret = newlen;out: if (wait_for_pid(pid)) WARN("do_cgm_get exited with error"); return ret;}
开发者ID:StarsoftInformatique,项目名称:lxc,代码行数:59,
示例11: CheckProgramBSONObj CheckProgram(const BSONObj& args, void* data) { ProcessId pid = ProcessId::fromNative(singleArg(args).numberInt()); int exit_code = -123456; // sentinel value bool isDead = wait_for_pid(pid, false, &exit_code); if (!isDead) { return BSON("" << BSON("alive" << true)); } return BSON("" << BSON("alive" << false << "exitCode" << exit_code));}
开发者ID:DINKIN,项目名称:mongo,代码行数:9,
示例12: RunProgram BSONObj RunProgram(const BSONObj &a) { ProgramRunner r( a, false ); r.start(); boost::thread t( r ); int exit_code; wait_for_pid(r.pid(), true, &exit_code); shells.erase( r.pid() ); return BSON( string( "" ) << exit_code ); }
开发者ID:jit,项目名称:mongo,代码行数:9,
示例13: RunProgram BSONObj RunProgram(const BSONObj &a, void* data) { ProgramRunner r( a ); r.start(); boost::thread t( r ); int exit_code = -123456; // sentinel value wait_for_pid(r.pid(), true, &exit_code); registry.deletePid( r.pid() ); return BSON( string( "" ) << exit_code ); }
开发者ID:ambroff,项目名称:mongo,代码行数:9,
示例14: pm_run_processpid_t pm_run_process(process_t *process){ if (process->env) process->env[process->env_c] = NULL; if (process->before) run_hook(BEFORE_HOOK, process); pid_t pid = pm_execute(1, (const char*)process->command, process->cd, (int)process->nice, (const char**)process->env); if (wait_for_pid(pid) < 0) return -1; if (process->after) run_hook(AFTER_HOOK, process); return pid;}
开发者ID:bharad,项目名称:babysitter,代码行数:10,
示例15: run_hookint run_hook(hook_t t, process_t *process){ pid_t pid = 0; if (t == BEFORE_HOOK) { pid = pm_execute(1, (const char*)process->before, (const char*)process->cd, (int)process->nice, (const char**)process->env); } else if (t == AFTER_HOOK) { pid = pm_execute(1, (const char*)process->after, (const char*)process->cd, (int)process->nice, (const char**)process->env); } return wait_for_pid(pid);}
开发者ID:bharad,项目名称:babysitter,代码行数:10,
示例16: WaitMongoProgramOnPort BSONObj WaitMongoProgramOnPort( const BSONObj &a, void* data ) { int port = oneArg( a ).numberInt(); uassert( 13621, "no known mongo program on port", dbs.count( port ) != 0 ); log() << "waiting port: " << port << ", pid: " << dbs[ port ].first << endl; bool ret = wait_for_pid( dbs[ port ].first ); if ( ret ) { dbs.erase( port ); } return BSON( "" << ret ); }
开发者ID:dibiasio,项目名称:mongo,代码行数:10,
示例17: RunMongoProgramBSONObj RunMongoProgram(const BSONObj& a, void* data) { BSONObj env{}; ProgramRunner r(a, env); r.start(); invariant(registry.isPidRegistered(r.pid())); stdx::thread t(r); registry.registerReaderThread(r.pid(), std::move(t)); int exit_code = -123456; // sentinel value wait_for_pid(r.pid(), true, &exit_code); return BSON(string("") << exit_code);}
开发者ID:DINKIN,项目名称:mongo,代码行数:11,
示例18: test_attach_lsm_cmdstatic int test_attach_lsm_cmd(struct lxc_container *ct){ int ret; pid_t pid; int pipefd[2]; char result[1024]; char *space; char *argv[] = {"cat", "/proc/self/attr/current", NULL}; lxc_attach_command_t command = {"cat", argv}; lxc_attach_options_t attach_options = LXC_ATTACH_OPTIONS_DEFAULT; TSTOUT("Testing attach lsm label with cmd.../n"); ret = pipe(pipefd); if (ret < 0) { TSTERR("pipe failed %d", ret); return ret; } attach_options.stdout_fd = pipefd[1]; ret = ct->attach(ct, lxc_attach_run_command, &command, &attach_options, &pid); if (ret < 0) { TSTERR("attach failed"); goto err1; } ret = read(pipefd[0], result, sizeof(result)-1); if (ret < 0) { TSTERR("read failed %d", ret); goto err2; } result[ret] = '/0'; space = strchr(result, '/n'); if (space) *space = '/0'; space = strchr(result, ' '); if (space) *space = '/0'; ret = -1; if (strcmp(lsm_label, result)) { TSTERR("LSM label mismatch expected:%s got:%s", lsm_label, result); goto err2; } ret = 0;err2: wait_for_pid(pid);err1: close(pipefd[0]); close(pipefd[1]); return ret;}
开发者ID:Azendale,项目名称:lxc,代码行数:53,
示例19: killDb int killDb( int port, pid_t _pid, int signal ) { pid_t pid; int exitCode = 0; if ( port > 0 ) { if( dbs.count( port ) != 1 ) { cout << "No db started on port: " << port << endl; return 0; } pid = dbs[ port ].first; } else { pid = _pid; } kill_wrapper( pid, signal, port ); int i = 0; for( ; i < 130; ++i ) { if ( i == 30 ) { char now[64]; time_t_to_String(time(0), now); now[ 20 ] = 0; cout << now << " process on port " << port << ", with pid " << pid << " not terminated, sending sigkill" << endl; kill_wrapper( pid, SIGKILL, port ); } if(wait_for_pid(pid, false, &exitCode)) break; sleepmillis( 1000 ); } if ( i == 130 ) { char now[64]; time_t_to_String(time(0), now); now[ 20 ] = 0; cout << now << " failed to terminate process on port " << port << ", with pid " << pid << endl; assert( "Failed to terminate process" == 0 ); } if ( port > 0 ) { close( dbs[ port ].second ); dbs.erase( port ); } else { close( shells[ pid ] ); shells.erase( pid ); } // FIXME I think the intention here is to do an extra sleep only when SIGKILL is sent to the child process. // We may want to change the 4 below to 29, since values of i greater than that indicate we sent a SIGKILL. if ( i > 4 || signal == SIGKILL ) { sleepmillis( 4000 ); // allow operating system to reclaim resources } return exitCode; }
开发者ID:dibiasio,项目名称:mongo,代码行数:53,
示例20: RunMongoProgram BSONObj RunMongoProgram( const BSONObj &a ) { ProgramRunner r( a ); r.start(); boost::thread t( r ); int exit_code; wait_for_pid( r.pid(), true, &exit_code ); if ( r.port() > 0 ) { dbs.erase( r.port() ); } else { shells.erase( r.pid() ); } return BSON( string( "" ) << exit_code ); }
开发者ID:jit,项目名称:mongo,代码行数:13,
示例21: RunMongoProgramBSONObj RunMongoProgram(const BSONObj& a, void* data) { ProgramRunner r(a); r.start(); stdx::thread t(r); int exit_code = -123456; // sentinel value wait_for_pid(r.pid(), true, &exit_code); if (r.port() > 0) { registry.deletePort(r.port()); } else { registry.deletePid(r.pid()); } return BSON(string("") << exit_code);}
开发者ID:wenhailong,项目名称:mongo,代码行数:13,
示例22: killDb int killDb( int port, pid_t _pid, int signal, const BSONObj& opt ) { pid_t pid; int exitCode = 0; if ( port > 0 ) { if( !registry.isPortRegistered( port ) ) { log() << "No db started on port: " << port << endl; return 0; } pid = registry.pidForPort( port ); } else { pid = _pid; } kill_wrapper( pid, signal, port, opt ); int i = 0; for( ; i < 130; ++i ) { if ( i == 60 ) { char now[64]; time_t_to_String(time(0), now); now[ 20 ] = 0; log() << now << " process on port " << port << ", with pid " << pid << " not terminated, sending sigkill" << endl; kill_wrapper( pid, SIGKILL, port, opt ); } if(wait_for_pid(pid, false, &exitCode)) break; sleepmillis( 1000 ); } if ( i == 130 ) { char now[64]; time_t_to_String(time(0), now); now[ 20 ] = 0; log() << now << " failed to terminate process on port " << port << ", with pid " << pid << endl; verify( "Failed to terminate process" == 0 ); } if ( port > 0 ) { registry.deletePort( port ); } else { registry.deletePid( pid ); } // FIXME I think the intention here is to do an extra sleep only when SIGKILL is sent to the child process. // We may want to change the 4 below to 29, since values of i greater than that indicate we sent a SIGKILL. if ( i > 4 || signal == SIGKILL ) { sleepmillis( 4000 ); // allow operating system to reclaim resources } return exitCode; }
开发者ID:89snake89,项目名称:mongo,代码行数:51,
示例23: do_mkfsstatic int do_mkfs(const char *path, const char *fstype){ pid_t pid; if ((pid = fork()) < 0) { ERROR("error forking"); return -1; } if (pid > 0) return wait_for_pid(pid); execlp("mkfs", "mkfs", "-t", fstype, path, NULL); exit(1);}
开发者ID:abstrakraft,项目名称:lxc-android-lxc,代码行数:14,
示例24: test_attach_funcstatic int test_attach_func(struct lxc_container *ct){ int ret; pid_t pid,nspid; int pipefd[2]; char result[1024]; lxc_attach_options_t attach_options = LXC_ATTACH_OPTIONS_DEFAULT; TSTOUT("Testing attach with func.../n"); /* XXX: We can't just use &nspid and have test_attach_func_func fill * it in because the function doesn't run in our process context but * in a fork()ed from us context. We read the result through a pipe. */ ret = pipe(pipefd); if (ret < 0) { TSTERR("pipe failed %d", ret); return ret; } attach_options.stdout_fd = pipefd[1]; ret = ct->attach(ct, test_attach_func_func, NULL, &attach_options, &pid); if (ret < 0) { TSTERR("attach failed"); goto err1; } ret = read(pipefd[0], result, sizeof(result)-1); if (ret < 0) { TSTERR("read failed %d", ret); goto err2; } result[ret] = '/0'; /* There is a small chance the pid is reused inside the NS, so we * just print it and don't actually do this check * * if (pid == nspid) TSTERR(...) */ nspid = atoi(result); TSTOUT("Pid:%d in NS:%d/n", pid, nspid); ret = 0;err2: wait_for_pid(pid);err1: close(pipefd[0]); close(pipefd[1]); return ret;}
开发者ID:Azendale,项目名称:lxc,代码行数:50,
示例25: killDb int killDb( int port, pid_t _pid, int signal ) { pid_t pid; int exitCode = 0; if ( port > 0 ) { if( dbs.count( port ) != 1 ) { cout << "No db started on port: " << port << endl; return 0; } pid = dbs[ port ].first; } else { pid = _pid; } kill_wrapper( pid, signal, port ); int i = 0; for( ; i < 130; ++i ) { if ( i == 30 ) { char now[64]; time_t_to_String(time(0), now); now[ 20 ] = 0; cout << now << " process on port " << port << ", with pid " << pid << " not terminated, sending sigkill" << endl; kill_wrapper( pid, SIGKILL, port ); } if(wait_for_pid(pid, false, &exitCode)) break; sleepmillis( 1000 ); } if ( i == 65 ) { char now[64]; time_t_to_String(time(0), now); now[ 20 ] = 0; cout << now << " failed to terminate process on port " << port << ", with pid " << pid << endl; assert( "Failed to terminate process" == 0 ); } if ( port > 0 ) { close( dbs[ port ].second ); dbs.erase( port ); } else { close( shells[ pid ] ); shells.erase( pid ); } if ( i > 4 || signal == SIGKILL ) { sleepmillis( 4000 ); // allow operating system to reclaim resources } return exitCode; }
开发者ID:jit,项目名称:mongo,代码行数:49,
示例26: test_attach_cmdstatic int test_attach_cmd(struct lxc_container *ct){ int ret; pid_t pid; char *argv[] = {"cmp", "-s", "/sbin/init", "/bin/busybox", NULL}; lxc_attach_command_t command = {"cmp", argv}; lxc_attach_options_t attach_options = LXC_ATTACH_OPTIONS_DEFAULT; TSTOUT("Testing attach with success command.../n"); ret = ct->attach(ct, lxc_attach_run_command, &command, &attach_options, &pid); if (ret < 0) { TSTERR("attach failed"); return ret; } ret = wait_for_pid(pid); if (ret < 0) { TSTERR("attach success command got bad return %d", ret); return ret; } TSTOUT("Testing attach with failure command.../n"); argv[2] = "/etc/fstab"; ret = ct->attach(ct, lxc_attach_run_command, &command, &attach_options, &pid); if (ret < 0) { TSTERR("attach failed"); return ret; } ret = wait_for_pid(pid); if (ret == 0) { TSTERR("attach failure command got bad return %d", ret); return -1; } return 0;}
开发者ID:Azendale,项目名称:lxc,代码行数:36,
示例27: pm_run_process/*** Run the process**/process_return_t* pm_run_process(process_t *process){ process_return_t* ret = pm_new_process_return(); // Setup the stdin int child_stdin; if (ret == NULL) return NULL; if (process->env) process->env[process->env_c] = NULL; // Run afterhook if (process->before) { if (run_hook(BEFORE_HOOK, process, ret)) return ret; } ret->stage = PRS_COMMAND; pid_t pid = pm_execute(1, (const char*)process->command, (const char*)process->cd, (int)process->nice, (const char**)process->env, &child_stdin, (const char*)process->stdout, (const char*)process->stderr); ret->pid = pid; ret->exit_status = wait_for_pid(pid, 0); if (ret->exit_status) { if (errno) { if (process->stdout) ret->stdout = read_from_file((const char*)process->stdout); if (process->stderr) ret->stderr = read_from_file((const char*)process->stderr); else { ret->stderr = (char*)calloc(1, sizeof(char)*strlen(strerror(errno))); strncpy(ret->stderr, strerror(errno), strlen(strerror(errno))); } } return ret; } // Run afterhook if (process->after) { if (run_hook(AFTER_HOOK, process, ret)) return ret; } // Yay, we finished properly ret->stage = PRS_OKAY; return ret;}
开发者ID:alepharchives,项目名称:babysitter,代码行数:50,
示例28: lvm_snapshotint lvm_snapshot(const char *orig, const char *path, uint64_t size){ int ret, pid; char sz[24], *pathdup, *lv; if ((pid = fork()) < 0) { SYSERROR("failed fork"); return -1; } if (pid > 0) return wait_for_pid(pid); // specify bytes to lvcreate ret = snprintf(sz, 24, "%"PRIu64"b", size); if (ret < 0 || ret >= 24) exit(EXIT_FAILURE); pathdup = strdup(path); if (!pathdup) exit(EXIT_FAILURE); lv = strrchr(pathdup, '/'); if (!lv) { free(pathdup); exit(EXIT_FAILURE); } *lv = '/0'; lv++; // check if the original lv is backed by a thin pool, in which case we // cannot specify a size that's different from the original size. ret = lvm_is_thin_volume(orig); if (ret == -1) { free(pathdup); return -1; } if (!ret) { ret = execlp("lvcreate", "lvcreate", "-s", "-L", sz, "-n", lv, orig, (char *)NULL); } else { ret = execlp("lvcreate", "lvcreate", "-s", "-n", lv, orig, (char *)NULL); } free(pathdup); exit(EXIT_FAILURE);}
开发者ID:4b42,项目名称:lxc,代码行数:45,
示例29: test_attach_lsm_funcstatic int test_attach_lsm_func(struct lxc_container *ct){ int ret; pid_t pid; int pipefd[2]; char result[1024]; lxc_attach_options_t attach_options = LXC_ATTACH_OPTIONS_DEFAULT; TSTOUT("Testing attach lsm label with func.../n"); ret = pipe(pipefd); if (ret < 0) { TSTERR("pipe failed %d", ret); return ret; } attach_options.stdout_fd = pipefd[1]; attach_options.attach_flags &= ~(LXC_ATTACH_LSM_EXEC|LXC_ATTACH_DROP_CAPABILITIES); attach_options.attach_flags |= LXC_ATTACH_LSM_NOW; ret = ct->attach(ct, test_attach_lsm_func_func, NULL, &attach_options, &pid); if (ret < 0) { TSTERR("attach failed"); goto err1; } ret = read(pipefd[0], result, sizeof(result)-1); if (ret < 0) { TSTERR("read failed %d", ret); goto err2; } result[ret] = '/0'; if (strcmp(lsm_label, result)) { TSTERR("LSM label mismatch expected:%s got:%s", lsm_label, result); ret = -1; goto err2; } ret = 0;err2: wait_for_pid(pid);err1: close(pipefd[0]); close(pipefd[1]); return ret;}
开发者ID:Azendale,项目名称:lxc,代码行数:45,
示例30: killDbint killDb(int port, ProcessId _pid, int signal, const BSONObj& opt) { ProcessId pid; int exitCode = 0; if (port > 0) { if (!registry.isPortRegistered(port)) { log() << "No db started on port: " << port; return 0; } pid = registry.pidForPort(port); } else { pid = _pid; } kill_wrapper(pid, signal, port, opt); bool processTerminated = false; bool killSignalSent = (signal == SIGKILL); for (int i = 0; i < 1300; ++i) { if (i == 600) { log() << "process on port " << port << ", with pid " << pid << " not terminated, sending sigkill"; kill_wrapper(pid, SIGKILL, port, opt); killSignalSent = true; } processTerminated = wait_for_pid(pid, false, &exitCode); if (processTerminated) { break; } sleepmillis(100); } if (!processTerminated) { severe() << "failed to terminate process on port " << port << ", with pid " << pid; invariant(false); } registry.deleteProgram(pid); if (killSignalSent) { sleepmillis(4000); // allow operating system to reclaim resources } return exitCode;}
开发者ID:paolo-comitini,项目名称:mongo,代码行数:43,
注:本文中的wait_for_pid函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ wait_for_until函数代码示例 C++ wait_for_file函数代码示例 |