Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/wait.h>
- #include <time.h>
- void nothing(){
- int x=0;
- x=x+1;
- }
- int main(){
- int i=1;
- int start=time(NULL);
- printf("Αρχική τιμή δευτερολέπτων %d\n", start);
- while(i<=100){
- if(fork()==0){
- //printf("I am %d child: %d and my parent is %d\n",i, getpid(),getppid());
- nothing();
- exit(0);
- }
- i++;
- }
- for (i=1;i<=100;i++){
- waitpid((pid_t)-1,NULL,0); //could do wait here instead?
- }
- int end=time(NULL);
- printf("Τελική τιμή δευτερολέπτων %d\n", end);
- printf("Diafora xronou %d\nMesos xronos %d\n", end-start,(end-start)/100);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement