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

This is a discussion on Procesees, fork(), wait() and exec() within the Linux Programming forums, part of the Platform Specific Boards category; Trying to learn about processes and such in UNIX. I wrote this little thing to help me try to understand. ...

  1. #1
    Stewdent
    Guest

    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.

    Code:
    #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
    Stewdent
    Guest
    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, 03:28 AM
  2. Signals, fork(), wait() and exec()
    By DJTurboToJo in forum C Programming
    Replies: 7
    Last Post: 03-18-2008, 10:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21