Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Thursday, April 18, 2024

File: [Platon] / ep / test / Attic / test_rur.c (download)

Revision 1.1.1.1 (vendor branch), Fri Sep 21 19:04:13 2001 UTC (22 years, 7 months ago) by host8


Changes since 1.1: +0 -0 lines

Initialization

#include <stdio.h>
#include <errno.h>
#include <signal.h>

#  include <stdlib.h>
#  include <string.h>

#  include <sys/types.h>
#  include <unistd.h>

#  include <sys/time.h>
#  include <time.h>
#  include <sys/wait.h>
#include <curses.h>

#define BUFSIZE 1024

    int
main(argc, argv)
    int argc;
    char **argv;
{
    fd_set fds;
    int pid;
    int pc[2];    // parent -> child  pipe
    int cp[2];    // child  -> parent pipe

    pipe(pc);
    pipe(cp);

    /* Fork processes and dump pipes. */
    switch (pid = fork()) {
        case -1:
            perror("Fork failure:");
            exit(errno);

            /* Child process. */
        case 0:    
            close(0);
            dup( pc[0]);
        //    close(1);
        //    dup(cp[1]);
            close(cp[0]);
            execvp(argv[1], argv+1);
            exit(errno);

            /* Parent process. */
        default:
            close(pc[0]);
            close(cp[1]);

            while (1) {

                FD_ZERO(&fds);
                FD_SET(0, &fds);
                switch (select(FD_SETSIZE, &fds, NULL, NULL, NULL)) {
                    case -1:
                        return errno;
                        break;

                    default:
                        if (FD_ISSET(0, &fds)) {
                            register int datasize;
                            char buf[BUFSIZE];

                            datasize = read(0, buf, BUFSIZE);
                            write(pc[1], buf, datasize);
                        }
                }
            }
    }
}

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top