2005-04-21 16:53:53 +02:00
|
|
|
/* test 4 */
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2011-12-16 15:45:53 +01:00
|
|
|
#include <errno.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
pid_t pid0, pid1, pid2, pid3;
|
2011-12-16 15:45:53 +01:00
|
|
|
int s, i, fd, nextb;
|
2005-04-21 16:53:53 +02:00
|
|
|
char *tempfile = "test4.temp";
|
|
|
|
char buf[1024];
|
2011-12-16 15:45:53 +01:00
|
|
|
|
2013-04-16 18:04:46 +02:00
|
|
|
int max_error = 2;
|
|
|
|
#include "common.h"
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2012-03-24 16:16:34 +01:00
|
|
|
int main(void);
|
|
|
|
void subr(void);
|
|
|
|
void nofork(void);
|
|
|
|
void quit(void);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int k;
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
start(4);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
creat(tempfile, 0777);
|
|
|
|
for (k = 0; k < 20; k++) {
|
|
|
|
subr();
|
|
|
|
}
|
|
|
|
unlink(tempfile);
|
|
|
|
quit();
|
|
|
|
return(-1); /* impossible */
|
|
|
|
}
|
|
|
|
|
|
|
|
void subr()
|
|
|
|
{
|
|
|
|
if ( (pid0 = fork()) != 0) {
|
|
|
|
/* Parent 0 */
|
|
|
|
if (pid0 < 0) nofork();
|
|
|
|
if ( (pid1 = fork()) != 0) {
|
|
|
|
/* Parent 1 */
|
|
|
|
if (pid1 < 0) nofork();
|
|
|
|
if ( (pid2 = fork()) != 0) {
|
|
|
|
/* Parent 2 */
|
|
|
|
if (pid2 < 0) nofork();
|
|
|
|
if ( (pid3 = fork()) != 0) {
|
|
|
|
/* Parent 3 */
|
|
|
|
if (pid3 < 0) nofork();
|
|
|
|
for (i = 0; i < 10000; i++);
|
2013-10-22 17:08:15 +02:00
|
|
|
kill(pid2, SIGKILL);
|
|
|
|
kill(pid1, SIGKILL);
|
|
|
|
kill(pid0, SIGKILL);
|
2005-04-21 16:53:53 +02:00
|
|
|
wait(&s);
|
|
|
|
wait(&s);
|
|
|
|
wait(&s);
|
|
|
|
wait(&s);
|
|
|
|
} else {
|
|
|
|
fd = open(tempfile, O_RDONLY);
|
|
|
|
lseek(fd, 20480L * nextb, 0);
|
|
|
|
for (i = 0; i < 10; i++) read(fd, buf, 1024);
|
|
|
|
nextb++;
|
|
|
|
close(fd);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while (1) getpid();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while (1) getpid();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while (1) getpid();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nofork()
|
|
|
|
{
|
|
|
|
int e = errno;
|
|
|
|
printf("Fork failed: %s (%d)\n",strerror(e),e);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|