本文整理汇总了C++中do_child函数的典型用法代码示例。如果您正苦于以下问题:C++ do_child函数的具体用法?C++ do_child怎么用?C++ do_child使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了do_child函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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.*/
}
示例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();
}
示例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 */
}
示例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*/
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
示例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*/
}
示例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);
}
示例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();
}
示例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);
}
示例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();
}
示例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();
}