Skip to content

Commit

Permalink
Step 4: timer
Browse files Browse the repository at this point in the history
  • Loading branch information
cnphil committed Apr 5, 2013
1 parent c28fda5 commit 771f238
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
6 changes: 5 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
all: MyCopy ForkCopy PipeCopy
all: MyCopy ForkCopy PipeCopy timer
clear:
rm *.o
MyCopy: MyCopy.o
Expand All @@ -13,3 +13,7 @@ PipeCopy: PipeCopy.o
g++ PipeCopy.o -o PipeCopy
PipeCopy.o:
g++ -c PipeCopy.c
timer: timer.o
g++ timer.o -o timer
timer.o:
g++ -c timer.c
Binary file added timer
Binary file not shown.
45 changes: 45 additions & 0 deletions timer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "cse356header.h"

main(int argc, char *argv[])
{
pid_t forkpid;

timeval start, stop;

forkpid = fork();

gettimeofday(&start, NULL);
if(forkpid == 0) {
execl("./MyCopy", "MyCopy", argv[1], argv[2], NULL);
exit(0);
}
wait(NULL);
gettimeofday(&stop, NULL);
printf("MyCopy took %lu\n", stop.tv_usec - start.tv_usec);


forkpid = fork();

gettimeofday(&start, NULL);
if(forkpid == 0) {
execl("./ForkCopy", "ForkCopy", argv[1], argv[2], NULL);
exit(0);
}
wait(NULL);
gettimeofday(&stop, NULL);
printf("ForkCopy took %lu\n", stop.tv_usec - start.tv_usec);


forkpid = fork();

gettimeofday(&start, NULL);
if(forkpid == 0) {
execl("./PipeCopy", "PipeCopy", argv[1], argv[2], NULL);
exit(0);
}
wait(NULL);
gettimeofday(&stop, NULL);
printf("PipeCopy took %lu\n", stop.tv_usec - start.tv_usec);

exit(0);
}

0 comments on commit 771f238

Please sign in to comment.