Example #1
0
int main(int argc, char *argv[])
{
	char	buf[512];
	int		pvec[2], duration;

	if (argc != 2) {
		fprintf(stderr,"Usage: %s duration\n", argv[0]);
		exit(1);
		}

	duration = atoi(argv[1]);

	pipe(pvec);

	wake_me(duration, report);
	iter = 0;

	while (1) {
		if (write(pvec[1], buf, sizeof(buf)) != sizeof(buf)) {
			if ((errno != EINTR) && (errno != 0))
				fprintf(stderr,"write failed, error %d\n", errno);
			}
		if (read(pvec[0], buf, sizeof(buf)) != sizeof(buf)) {
			if ((errno != EINTR) && (errno != 0))
				fprintf(stderr,"read failed, error %d\n", errno);
			}
		iter++;
	}
}
Example #2
0
/*******************************************************
 * Signal routing
 ******************************************************/
int wait_sig (int signum, void (*func)(int signum)) {
   /* shutup gcc */
    (void)signum;
    /* set up the signal */
    signal (signum, func);
    /* set up the time out handler, 
       in case of some kind of unexpected errors */
    wake_me (10, resume_timeout);
}
Example #3
0
int main(int argc, char *argv[])
{
    int	slave, duration;
    int	status;

    if (argc != 2) {
        fprintf(stderr,"Usage: %s duration \n", argv[0]);
        exit(1);
    }

    duration = atoi(argv[1]);

    iter = 0;
    wake_me(duration, report);

    while (1) {
        if ((slave = fork()) == 0) {
            /* slave .. boring */
#if debug
            printf("fork OK\n");
#endif
            /* kill it right away */
            exit(0);
        } else if (slave < 0) {
            /* woops ... */
            fprintf(stderr,"Fork failed at iteration %lu\n", iter);
            perror("Reason");
            exit(2);
        } else
            /* master */
            wait(&status);
        if (status != 0) {
            fprintf(stderr,"Bad wait status: 0x%x\n", status);
            exit(2);
        }
        iter++;
#if debug
        printf("Child %d done.\n", slave);
#endif
    }
}
Example #4
0
int main(int argc, char *argv[])
{
	int disk=10, /* default number of disks */
         duration;

	if (argc < 2) {
		fprintf(stderr,"Usage: %s duration [disks]\n", argv[0]);
		exit(1);
		}
	duration = atoi(argv[1]);
	if(argc > 2) disk = atoi(argv[2]);
	num[1] = disk;

	wake_me(duration, report);

	while(1) {
		mov(disk,1,3);
		iter++;
		}

	exit(0);
}
Example #5
0
int main(int argc, char *argv[])
{
        char   *test;
	int	duration;

	if (argc < 2) {
		fprintf(stderr,"Usage: %s duration [ test ]\n", argv[0]);
                fprintf(stderr,"test is one of:\n");
                fprintf(stderr,"  \"mix\" (default), \"close\", \"getpid\", \"exec\"\n");
		exit(1);
	}
        if (argc > 2)
            test = argv[2];
        else
            test = "mix";

	duration = atoi(argv[1]);

	iter = 0;
	wake_me(duration, report);

        switch (test[0]) {
        case 'm':
	   while (1) {
		close(dup(0));
		getpid();
		getuid();
		umask(022);
		iter++;
	   }
	   /* NOTREACHED */
        case 'c':
           while (1) {
                close(dup(0));
                iter++;
           }
           /* NOTREACHED */
        case 'g':
           while (1) {
                getpid();
                iter++;
           }
           /* NOTREACHED */
        case 'e':
           while (1) {
                pid_t pid = fork();
                if (pid < 0) {
                    fprintf(stderr,"%s: fork failed\n", argv[0]);
                    exit(1);
                } else if (pid == 0) {
                    execl("/usr/bin/true", (char *) 0);
                    fprintf(stderr,"%s: exec /usr/bin/true failed\n", argv[0]);
                    exit(1);
                } else {
                    if (waitpid(pid, NULL, 0) < 0) {
                        fprintf(stderr,"%s: waitpid failed\n", argv[0]);
                        exit(1);
                    }
                }
                iter++;
           }
           /* NOTREACHED */
        }

        exit(9);
}
Example #6
0
int pipe_loop() {
    unsigned long check;
    pid_t pid;

    /* Hope the sleep will help the top process
     * finish the forkes, at least most of them*/
    sleep (1);

    if (pipe (p1) || pipe (p2)) {
        perror ("pipe created failed");
        exit (ERR_PIP);
    }

    if ((pid = fork()) < 0) {
#ifdef DEBUG
        perror ("fork failed\n");
#endif
        exit (ERR_FRK);
    }

    if (pid > 0) {
        /* parent process */

#if 0
        /***************************************************
        * Set up the signal
        * only after receiving the SIGUSR1 signal
        * transfer is started
        **************************************************/
        wait_sig (SIGUSR1, resume);
        pause ();
#endif

        /* set up the timer */
        wake_me (duration, report);

        /* master, write p1 & read p2 */
        close(p1[0]); close(p2[1]);
        while (1) {
            if (write(p1[1], (char *)&iter, sizeof(iter)) != sizeof(iter)) {
#ifdef NDEBUG
                if ((errno != 0) && (errno != EINTR))
                    perror("master write failed");
#endif
                exit(ERR_WRI);
            }

            if (read(p2[0], (char *)&check, sizeof(check)) != sizeof(check)) {
#ifdef NDDEBUG
                if ((errno != 0) && (errno != EINTR))
                    perror("master read failed");
#endif
                exit(ERR_RED);
            }

            if (check != iter) {
#ifdef DEBUG
                printf("Master sync error: expect %lu, got %lu\n",
                       iter, check);
#endif
                exit(ERR_SYN);
            }
            iter++;
        }
    }
    /* child process */

#if 0
    /**************************************************
     * Child processes must ignore the signal SIGUSR1
     * otherwise will be corrupted. Also this would
     * prevent overhead casued by signal handling
     **************************************************/
    signal (SIGUSR1, SIG_IGN);
#endif


    unsigned long iter1;
    iter1 = 0;
    /* slave, read p1 & write p2 */
    close(p1[1]); close(p2[0]);
    while (1) {
        if (read(p1[0], (char *)&check, sizeof(check)) != sizeof(check)) {
#ifdef NDEBUG
            if ((errno != 0) && (errno != EINTR))
                perror("slave read failed");
#endif
            exit(ERR_RED);
        }

        if (check != iter1) {
#ifdef DEBUG
            printf("Slave sync error: expect %lu, got %lu\n",
                   iter1, check);
#endif
            exit(ERR_SYN);
        }
        if (write(p2[1], (char *)&iter1, sizeof(iter1)) != sizeof(iter1)) {
#ifdef NDEBUG
            if ((errno != 0) && (errno != EINTR))
                perror("slave write failed");
#endif
            exit(ERR_WRI);
        }
        iter1++;
    }
    return 0;
}
Example #7
0
int main(int argc, char *argv[])
{
int	slave, count, duration;
int	status;

if (argc < 2)
	{
	fprintf(stderr,"Usage: %s duration command [args..]\n", argv[0]);
	fprintf(stderr,"  duration in seconds\n");
	exit(1);
	}

if((duration = atoi(argv[1])) < 1)
	{
	fprintf(stderr,"Usage: %s duration command [arg..]\n", argv[0]);
	fprintf(stderr,"  duration in seconds\n");
	exit(1);
	}

/* get command  */
cmd_argc=argc-2;
for( count=2;count < argc; ++count)
	cmd_argv[count-2]=argv[count];
#ifdef DEBUG
printf("<<%s>>",cmd_argv[0]);
for(count=1;count < cmd_argc; ++count)
	printf(" <%s>", cmd_argv[count]);
putchar('\n');
exit(0);
#endif

iter = 0;
wake_me(duration, report);

while (1)
	{
	if ((slave = fork()) == 0)
		{ /* execute command */
		execvp(cmd_argv[0],cmd_argv);
		exit(99);
		}
	else if (slave < 0)
		{
		/* woops ... */
		fprintf(stderr,"Fork failed at iteration %lu\n", iter);
		perror("Reason");
		exit(2);
		}
	else
		/* master */
		wait(&status);
        if (status == 99 << 8)
                {
                fprintf(stderr, "Command \"%s\" didn't exec\n", cmd_argv[0]);
                exit(2);
                }
	else if (status != 0)
		{
		fprintf(stderr,"Bad wait status: 0x%x\n", status);
		exit(2);
		}
	iter++;
	}
}