kernel
#include<sys/types.h>
#include<sys/wait.h>
#include<unistd.h>
#include<time.h>
#include<sys/times.h>
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i, status;
pid_t pid;
time_t currentTime;
struct tms cpuTime;
if((pid = fork())==-1)
{
perror("\nfork error");
exit(EXIT_FAILURE);
}
else if(pid==0)
{
time(¤tTime);
printf("\nChild process started at %s",ctime(¤tTime));
for(i=0;i<5;i++)
{printf("\nCounting= %dn",i);
sleep(1);
}
time(¤tTime);
printf("\nChild process ended at %s",ctime(¤tTime));
exit(EXIT_SUCCESS);
}
else
{
time(¤tTime);
printf("\nParent process started at %s ",ctime(¤tTime));
if(wait(&status)== -1)
perror("\n wait error");
if(WIFEXITED(status))
printf("\nChild process ended normally");
else
printf("\nChild process did not end normally");
if(times(&cpuTime)<0)
perror("\nTimes error");
else
{
printf("\nParent process user time= %fn",((double)
cpuTime.tms_utime));
printf("\nParent process system time = %fn",((double)
cpuTime.tms_stime));
printf("\nChild process user time = %fn",((double)
cpuTime.tms_cutime));
printf("\nChild process system time = %fn",((double)
cpuTime.tms_cstime));
}
time(¤tTime);
printf("\nParent process ended at %s",ctime(¤tTime));
exit(EXIT_SUCCESS);
}
}