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.