2005-04-21 16:53:53 +02:00
|
|
|
/* test 10 */
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
char *name[] = {"t10a", "t10b", "t10c", "t10d", "t10e", "t10f", "t10g",
|
|
|
|
"t10h", "t10i", "t10j"};
|
2012-04-08 19:22:02 +02:00
|
|
|
|
|
|
|
#define PROGBUF_LONGS 3000
|
|
|
|
long prog[PROGBUF_LONGS];
|
2005-04-21 16:53:53 +02:00
|
|
|
int psize;
|
|
|
|
|
2013-04-16 18:04:46 +02:00
|
|
|
int max_error = 2;
|
|
|
|
#include "common.h"
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
|
2012-03-24 16:16:34 +01:00
|
|
|
int main(void);
|
|
|
|
void spawn(int n);
|
|
|
|
void mkfiles(void);
|
|
|
|
void cr_file(char *name, int size);
|
|
|
|
void rmfiles(void);
|
|
|
|
void quit(void);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int i, n, pid, r;
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
start(10);
|
|
|
|
system("cp ../t10a .");
|
2005-04-21 16:53:53 +02:00
|
|
|
pid = getpid();
|
|
|
|
|
|
|
|
/* Create files t10b ... t10h */
|
|
|
|
mkfiles();
|
|
|
|
|
|
|
|
if (getpid() == pid)
|
|
|
|
if (fork() == 0) {
|
2011-11-28 11:07:55 +01:00
|
|
|
execl("t10a", "t10a", (char *) 0);
|
2005-04-21 16:53:53 +02:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
if (getpid() == pid)
|
|
|
|
if (fork() == 0) {
|
2011-11-28 11:07:55 +01:00
|
|
|
execl("t10b", "t10b", (char *) 0);
|
2005-04-21 16:53:53 +02:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
if (getpid() == pid)
|
|
|
|
if (fork() == 0) {
|
2011-11-28 11:07:55 +01:00
|
|
|
execl("t10c", "t10c", (char *) 0);
|
2005-04-21 16:53:53 +02:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
if (getpid() == pid)
|
|
|
|
if (fork() == 0) {
|
2011-11-28 11:07:55 +01:00
|
|
|
execl("t10d", "t10d", (char *) 0);
|
2005-04-21 16:53:53 +02:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
srand(100);
|
|
|
|
for (i = 0; i < 60; i++) {
|
|
|
|
r = rand() & 07;
|
|
|
|
spawn(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) wait(&n);
|
|
|
|
rmfiles();
|
|
|
|
quit();
|
|
|
|
return(-1); /* impossible */
|
|
|
|
}
|
|
|
|
|
|
|
|
void spawn(n)
|
|
|
|
int n;
|
|
|
|
{
|
2013-01-07 17:19:30 +01:00
|
|
|
int pid;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2011-11-14 11:07:49 +01:00
|
|
|
if ((pid = fork()) != 0) {
|
2005-04-21 16:53:53 +02:00
|
|
|
wait(&n); /* wait for some child (any one) */
|
|
|
|
} else {
|
2013-02-04 01:49:48 +01:00
|
|
|
/* a successful exec or a successful detection of a broken executable
|
|
|
|
* is ok
|
|
|
|
*/
|
|
|
|
if(execl(name[n], name[n], (char *) 0) < 0 && errno == ENOEXEC)
|
|
|
|
exit(0);
|
2005-04-21 16:53:53 +02:00
|
|
|
errct++;
|
|
|
|
printf("Child execl didn't take. file=%s errno=%d\n", name[n], errno);
|
|
|
|
rmfiles();
|
|
|
|
exit(1);
|
|
|
|
printf("Worse yet, EXIT didn't exit\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mkfiles()
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
fd = open("t10a", 0);
|
|
|
|
if (fd < 0) {
|
|
|
|
printf("Can't open t10a\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-04-08 19:22:02 +02:00
|
|
|
psize = read(fd, (char *) prog, PROGBUF_LONGS * 4);
|
2005-04-21 16:53:53 +02:00
|
|
|
cr_file("t10b", 1600);
|
|
|
|
cr_file("t10c", 1400);
|
|
|
|
cr_file("t10d", 2300);
|
|
|
|
cr_file("t10e", 3100);
|
|
|
|
cr_file("t10f", 2400);
|
|
|
|
cr_file("t10g", 1700);
|
|
|
|
cr_file("t10h", 1500);
|
|
|
|
cr_file("t10i", 4000);
|
|
|
|
cr_file("t10j", 2250);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cr_file(name, size)
|
|
|
|
char *name;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
2012-04-08 19:22:02 +02:00
|
|
|
size += 3000;
|
2005-04-21 16:53:53 +02:00
|
|
|
fd = creat(name, 0755);
|
|
|
|
write(fd, (char *) prog, psize);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rmfiles()
|
|
|
|
{
|
|
|
|
unlink("t10b");
|
|
|
|
unlink("t10c");
|
|
|
|
unlink("t10d");
|
|
|
|
unlink("t10e");
|
|
|
|
unlink("t10f");
|
|
|
|
unlink("t10g");
|
|
|
|
unlink("t10h");
|
|
|
|
unlink("t10i");
|
|
|
|
unlink("t10j");
|
|
|
|
}
|
|
|
|
|