Thread: Procesees, fork(), wait() and exec()

  1. #1

    Procesees, fork(), wait() and exec()

    Trying to learn about processes and such in UNIX.
    I wrote this little thing to help me try to understand.

    #include <stdio.h>
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/time.h>
    #include <sys/wait.h>
    #include <sys/resource.h>
    void child( char *command, char *arg[] );
    int main()
        char *arg[3], *tm;
        char *command = "ls";
        struct rusage *data;
        int pid, w_child;
        pid = fork();
        if( pid == 0 )
            child( command, arg);
        else if( pid > 0 )
            w_child = wait3(NULL, 0, data);
        /* HOW do i get access to statistics from wait3()
        tm = ctime((data.ru_utime)->tv_sec);
        printf( "%s\n", tm);
        printf( "END: you should see 'ls -l'.\n" );
        printf( "The parent pid is: %d\n", getpid() );
        printf( "The child pid was: %d\n", w_child );
        return 0;
    void child( char *command, char *arg[] )
        arg[0] = "";
        arg[1] = "-l";
        arg[2] = 0;
        execvp( command, arg );
    Can someone help me with the correct way to access the data from the rusage struct. I would like to be able to generate a line which shows the system, user and real time used by the process, but am confused on how to get data.

    Any pointers (sorry, bad joke) would be appreciated.

  2. #2
    Thanks for the quick reply, just what I needed!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why wait cursor still turning on?
    By Opariti in forum Windows Programming
    Replies: 0
    Last Post: 05-22-2009, 02:28 AM
  2. Signals, fork(), wait() and exec()
    By DJTurboToJo in forum C Programming
    Replies: 7
    Last Post: 03-18-2008, 09:14 AM