本文整理汇总了C++中do_child函数的典型用法代码示例。如果您正苦于以下问题:C++ do_child函数的具体用法?C++ do_child怎么用?C++ do_child使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了do_child函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv) {
int forkres, i;
/* Get subtest number */
if(argc != 2) {
printf("Usage: %s subtest_no\n", argv[0]);
exit(-2);
} else if(sscanf(argv[1], "%d", &subtest) != 1) {
printf("Usage: %s subtest_no\n", argv[0]);
exit(-2);
}
/* Fork off a bunch of children */
for(i = 0; i < NUMCHILDREN; i++) {
forkres = fork();
if(forkres == 0) do_child(i);
else if(forkres < 0) {
perror("Unable to fork");
exit(-1);
}
}
/* do_child always calls exit(), so when we end up here, we're the parent. */
do_parent();
exit(-2); /* We're not supposed to get here. Both do_* routines should exit.*/
}
开发者ID:AjeyBohare,项目名称:minix,代码行数:26,代码来源:t40e.c
示例2: main
int main(int ac, char **av)
{
pid_t pid;
int status;
tst_parse_opts(ac, av, options, NULL);
if (sflag)
hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);
setup();
switch (pid = fork()) {
case -1:
tst_brkm(TBROK | TERRNO, cleanup, "fork");
case 0:
/* set the user ID of the child to the non root user */
if (setuid(ltp_uid) == -1)
tst_brkm(TBROK | TERRNO, cleanup, "setuid");
do_child();
tst_exit();
default:
if (waitpid(pid, &status, 0) == -1)
tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
}
cleanup();
tst_exit();
}
开发者ID:CSRedRat,项目名称:ltp,代码行数:28,代码来源:hugeshmctl03.c
示例3: main
int main(void)
{
pid_t r;
subtest = 1;
#ifdef __GNUC__
printf("Test 52 (GCC) ");
#else
printf("Test 52 (ACK) ");
#endif
fflush(stdout);
if (pipe(pipefdc) == -1) err(1);
if (pipe(pipefdp) == -1) err(2);
r = fork();
if(r < 0) {
err(3);
} else if(r == 0) {
/* Child */
do_child();
} else {
/* Parent */
do_parent();
}
return(0); /* Never reached */
}
开发者ID:Spenser309,项目名称:CS551,代码行数:29,代码来源:test52.c
示例4: main
int main(int argc, char **argv) {
int forkres;
/* Get subtest number */
if(argc != 2) {
printf("Usage: %s subtest_no\n", argv[0]);
exit(-2);
} else if(sscanf(argv[1], "%d", &subtest) != 1) {
printf("Usage: %s subtest_no\n", argv[0]);
exit(-2);
}
/* Set up anonymous pipe */
if(pipe(fd_ap) < 0) {
perror("Could not create anonymous pipe");
exit(-1);
}
forkres = fork();
if(forkres == 0) do_child();
else if(forkres > 0) do_parent(forkres);
else { /* Fork failed */
perror("Unable to fork");
exit(-1);
}
exit(-2); /* We're not supposed to get here. Both do_* routines should exit*/
}
开发者ID:AgamAgarwal,项目名称:minix,代码行数:29,代码来源:t40f.c
示例5: start_server
pid_t
start_server(struct sockaddr_in *ssin, struct sockaddr_un *ssun)
{
pid_t pid;
sfd = socket(PF_INET, SOCK_STREAM, 0);
if (sfd < 0)
return -1;
if (bind(sfd, (struct sockaddr *)ssin, sizeof(*ssin)) < 0)
return -1;
if (listen(sfd, 10) < 0)
return -1;
/* set up UNIX-domain socket */
ufd = socket(PF_UNIX, SOCK_STREAM, 0);
if (ufd < 0)
return -1;
if (bind(ufd, (struct sockaddr *)ssun, sizeof(*ssun)))
return -1;
if (listen(ufd, 10) < 0)
return -1;
switch (pid = fork()) {
case 0: /* child */
do_child();
break;
case -1: /* fall through */
default: /* parent */
(void)close(sfd);
return pid;
}
return -1;
}
开发者ID:Open-Party,项目名称:systemtap,代码行数:34,代码来源:recvmmsg.c
示例6: main
int main(int ac, char **av)
{
int pid;
void do_child(void);
tst_parse_opts(ac, av, NULL, NULL);
setup(); /* global setup */
if ((pid = FORK_OR_VFORK()) == -1) {
tst_brkm(TBROK, cleanup, "could not fork");
}
if (pid == 0) { /* child */
/* set the user ID of the child to the non root user */
if (setuid(ltp_uid) == -1) {
tst_resm(TBROK, "setuid() failed");
exit(1);
}
do_child();
} else {
/* wait for the child to return */
SAFE_WAITPID(cleanup, pid, NULL, 0);
/* if it exists, remove the shared memory resource */
rm_shm(shm_id_1);
tst_rmdir();
}
cleanup();
tst_exit();
}
开发者ID:kraj,项目名称:ltp,代码行数:34,代码来源:shmctl03.c
示例7: start_server
pid_t
start_server(struct sockaddr_in *sin0)
{
struct sockaddr_in sin1 = *sin0;
pid_t pid;
sfd = socket(PF_INET, SOCK_STREAM, 0);
if (sfd < 0)
return -1;
if (bind(sfd, (struct sockaddr *)&sin1, sizeof(sin1)) < 0)
return -1;
if (listen(sfd, 10) < 0)
return -1;
switch (pid = fork()) {
case 0: /* child */
do_child();
break;
case -1: /* fall through */
default: /* parent */
(void)close(sfd);
return pid;
}
return -1;
}
开发者ID:h4ck3rm1k3,项目名称:systemtap,代码行数:26,代码来源:recvfrom.c
示例8: main
int main(int ac, char **av)
{
const char *msg;
int status;
pid_t pid;
msg = parse_opts(ac, av, options, &help);
if (msg != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
if (sflag)
hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);
setup();
switch (pid = fork()) {
case -1:
tst_brkm(TBROK | TERRNO, cleanup, "fork");
case 0:
if (setuid(ltp_uid) == -1)
tst_brkm(TBROK | TERRNO, cleanup, "setuid");
do_child();
tst_exit();
default:
if (waitpid(pid, &status, 0) == -1)
tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
}
cleanup();
tst_exit();
}
开发者ID:MohdVara,项目名称:ltp,代码行数:30,代码来源:hugeshmat03.c
示例9: do_child_uclinux
/*
* do_child_uclinux() - capture signals again, then run do_child()
*/
void
do_child_uclinux()
{
tst_sig(FORK, sighandler, cleanup);
do_child();
}
开发者ID:boostsup,项目名称:minix3,代码行数:10,代码来源:msgrcv06.c
示例10: main
int main(int argc, char **argv) {
int forkres;
int master, slave;
/* Get subtest number */
if(argc != 2) {
printf("Usage: %s subtest_no\n", argv[0]);
exit(-1);
} else if(sscanf(argv[1], "%d", &subtest) != 1) {
printf("Usage: %s subtest_no\n", argv[0]);
exit(-1);
}
open_terminal(&master, &slave);
forkres = fork();
if(forkres == 0) do_child(master);
else if(forkres > 0) do_parent(forkres, slave);
else { /* Fork failed */
perror("Unable to fork");
exit(-1);
}
exit(-2); /* We're not supposed to get here. Both do_* routines should exit*/
}
开发者ID:mluszczyk,项目名称:so-minix,代码行数:26,代码来源:t40c.c
示例11: main
int main(void)
{
int sp[2];
if (-1 == socketpair(AF_UNIX, SOCK_STREAM, 0, sp)) {
fprintf(stderr, "socketpair(): %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
switch (fork()) {
case -1:
fprintf(stderr, "fork(): %s\n", strerror(errno));
exit(EXIT_FAILURE);
case 0:
close(sp[0]);
do_child(sp[1]);
break;
default:
close(sp[1]);
do_parent(sp[0]);
break;
}
exit(EXIT_SUCCESS);
}
开发者ID:bdrewery,项目名称:launchd-for-freebsd,代码行数:25,代码来源:missed-EVFILT_WRITE.c
示例12: main
int main(int ac, char **av)
{
int lc;
int i;
tst_parse_opts(ac, av, NULL, NULL);
setup();
for (lc = 0; TEST_LOOPING(lc); lc++) {
tst_count = 0;
for (i = 0; i < TST_TOTAL; ++i) {
pid2 = tst_fork();
if (pid2 == -1)
tst_brkm(TBROK, cleanup, "fork failed");
if (!pid2)
do_child(&test_cases[i]);
else
tst_record_childstatus(cleanup, pid2);
tst_count++;
}
}
cleanup();
tst_exit();
}
开发者ID:AiprNick,项目名称:ltp,代码行数:28,代码来源:kcmp01.c
示例13: main
int main(int ac, char **av)
{
int lc; /* loop counter */
char *msg; /* message returned from parse_opts */
/* parse standard options */
if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){
tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
}
#ifdef UCLINUX
maybe_run_child(&do_child_uclinux, "d", &msg_q_1);
#endif
setup(); /* global setup */
/* The following loop checks looping state if -i option given */
for (lc = 0; TEST_LOOPING(lc); lc++) {
/* reset Tst_count in case we are looping */
Tst_count = 0;
/*
* fork a child that will attempt to read a non-existent
* message from the queue
*/
if ((c_pid = FORK_OR_VFORK()) == -1) {
tst_brkm(TBROK, cleanup, "could not fork");
}
if (c_pid == 0) { /* child */
/*
* Attempt to read a message without IPC_NOWAIT.
* With no message to read, the child sleeps.
*/
#ifdef UCLINUX
if (self_exec(av[0], "d", msg_q_1) < 0) {
tst_brkm(TBROK, cleanup, "could not self_exec");
}
#else
do_child();
#endif
} else { /* parent */
usleep(250000);
/* send a signal that must be caught to the child */
if (kill(c_pid, SIGHUP) == -1) {
tst_brkm(TBROK, cleanup, "kill failed");
}
waitpid(c_pid, NULL, 0);
}
}
cleanup();
/*NOTREACHED*/
return(0);
}
开发者ID:boostsup,项目名称:minix3,代码行数:59,代码来源:msgrcv05.c
示例14: do_child_uclinux
/*
* do_child_uclinux() - as above, but mallocs rdbuf first
*/
void do_child_uclinux()
{
if ((rdbuf = (char *)malloc(szcharbuf)) == (char *)0) {
tst_brkm(TBROK, cleanup, "malloc of rdbuf failed");
}
do_child();
}
开发者ID:Mellanox,项目名称:arc_ltp,代码行数:11,代码来源:pipe11.c
示例15: do_child_uclinux
/*
* do_child_uclinux() - as above, but mallocs rdbuf first
*/
void do_child_uclinux(void)
{
if ((rdbuf = malloc(szcharbuf)) == NULL) {
tst_brkm(TBROK, cleanup, "malloc of rdbuf failed");
}
do_child();
}
开发者ID:1587,项目名称:ltp,代码行数:11,代码来源:pipe11.c
示例16: do_test
static void do_test(int i)
{
pid_t cpid;
cpid = tst_fork();
if (cpid < 0)
tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");
if (cpid == 0)
do_child(i);
fd = SAFE_OPEN(cleanup, "file", O_RDONLY);
TEST(fcntl(fd, F_SETLEASE, test_cases[i].lease_type));
if (TEST_RETURN == -1) {
tst_resm(TFAIL | TTERRNO, "fcntl() failed to set lease");
SAFE_WAITPID(cleanup, cpid, NULL, 0);
SAFE_CLOSE(cleanup, fd);
fd = 0;
return;
}
/* Wait for SIGIO caused by lease breaker. */
TEST(sigtimedwait(&newset, NULL, &timeout));
if (TEST_RETURN == -1) {
if (TEST_ERRNO == EAGAIN) {
tst_resm(TFAIL | TTERRNO, "failed to receive SIGIO "
"within %lis", timeout.tv_sec);
SAFE_WAITPID(cleanup, cpid, NULL, 0);
SAFE_CLOSE(cleanup, fd);
fd = 0;
return;
}
tst_brkm(TBROK | TTERRNO, cleanup, "sigtimedwait() failed");
}
/* Try to downgrade or remove the lease. */
switch (test_cases[i].lease_type) {
case F_WRLCK:
TEST(fcntl(fd, F_SETLEASE, F_RDLCK));
if (TEST_RETURN == 0)
break;
case F_RDLCK:
TEST(fcntl(fd, F_SETLEASE, F_UNLCK));
if (TEST_RETURN == -1) {
tst_resm(TFAIL | TTERRNO,
"fcntl() failed to remove the lease");
}
break;
default:
break;
}
tst_record_childstatus(cleanup, cpid);
SAFE_CLOSE(cleanup, fd);
fd = 0;
}
开发者ID:CSRedRat,项目名称:ltp,代码行数:58,代码来源:fcntl33.c
示例17: main
/* The code should barf on TDBs created with rwlocks. */
int main(int argc, char *argv[])
{
struct tdb_context *tdb;
unsigned int log_count;
struct tdb_logging_context log_ctx = { log_fn, &log_count };
int ret, status;
pid_t child, wait_ret;
int fromchild[2];
int tochild[2];
char c;
int tdb_flags;
bool runtime_support;
runtime_support = tdb_runtime_check_for_robust_mutexes();
if (!runtime_support) {
skip(1, "No robust mutex support");
return exit_status();
}
key.dsize = strlen("hi");
key.dptr = discard_const_p(uint8_t, "hi");
data.dsize = strlen("world");
data.dptr = discard_const_p(uint8_t, "world");
pipe(fromchild);
pipe(tochild);
tdb_flags = TDB_INCOMPATIBLE_HASH|
TDB_MUTEX_LOCKING|
TDB_CLEAR_IF_FIRST;
child = fork();
if (child == 0) {
close(fromchild[0]);
close(tochild[1]);
return do_child(tdb_flags, fromchild[1], tochild[0]);
}
close(fromchild[1]);
close(tochild[0]);
read(fromchild[0], &c, sizeof(c));
tdb = tdb_open_ex("mutex-allrecord-trylock.tdb", 0, tdb_flags,
O_RDWR|O_CREAT, 0755, &log_ctx, NULL);
ok(tdb, "tdb_open_ex should succeed");
ret = tdb_allrecord_lock(tdb, F_WRLCK, TDB_LOCK_NOWAIT, false);
ok(ret == -1, "tdb_allrecord_lock (nowait) should not succeed");
write(tochild[1], &c, sizeof(c));
wait_ret = wait(&status);
ok(wait_ret == child, "child should have exited correctly");
diag("done");
return exit_status();
}
开发者ID:Alexander--,项目名称:samba,代码行数:59,代码来源:run-mutex-allrecord-trylock.c
示例18: do_child_uclinux
/*
* do_child_uclinux() - capture signals again, then run do_child()
*/
void do_child_uclinux()
{
if (sync_pipe_create(sync_pipes, PIPE_NAME) == -1)
tst_brkm(TBROK, cleanup, "sync_pipe_create failed");
tst_sig(FORK, SIG_IGN, cleanup);
do_child();
}
开发者ID:Altiscale,项目名称:sig-core-t_ltp,代码行数:12,代码来源:msgrcv06.c
示例19: main
int main(int argc, char** argv)
{
// We need to keep the original parameters in order to pass them to the
// model-checked process:
int argc_copy = argc;
char** argv_copy = argvdup(argc, argv);
xbt_log_init(&argc_copy, argv_copy);
sg_config_init(&argc_copy, argv_copy);
if (argc < 2)
xbt_die("Missing arguments.\n");
bool server_mode = true;
char* env = std::getenv("SIMGRID_MC_MODE");
if (env) {
if (std::strcmp(env, "server") == 0)
server_mode = true;
else if (std::strcmp(env, "standalone") == 0)
server_mode = false;
else
xbt_die("Unrecognised value for SIMGRID_MC_MODE (server/standalone)");
}
if (!server_mode) {
setenv(MC_ENV_VARIABLE, "1", 1);
execvp(argv[1], argv+1);
std::perror("simgrid-mc");
return 127;
}
// Create a AF_LOCAL socketpair:
int res;
int sockets[2];
res = socketpair(AF_LOCAL, SOCK_DGRAM | SOCK_CLOEXEC, 0, sockets);
if (res == -1) {
perror("simgrid-mc");
return MC_SERVER_ERROR;
}
XBT_DEBUG("Created socketpair");
pid_t pid = fork();
if (pid < 0) {
perror("simgrid-mc");
return MC_SERVER_ERROR;
} else if (pid == 0) {
close(sockets[1]);
return do_child(sockets[0], argv);
} else {
close(sockets[0]);
return do_parent(sockets[1], pid);
}
return 0;
}
开发者ID:tempbottle,项目名称:simgrid,代码行数:57,代码来源:simgrid_mc.cpp
示例20: do_child_uclinux
/*
* do_child_uclinux() - capture signals, initialize buffer, then run do_child()
*/
void do_child_uclinux(void)
{
/* initialize the message buffer */
init_buf(&msg_buf, MSGTYPE, MSGSIZE);
tst_sig(FORK, sighandler, cleanup);
do_child();
}
开发者ID:Nan619,项目名称:ltp,代码行数:12,代码来源:msgsnd05.c
注:本文中的do_child函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论