-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a14f72f
commit 93f0120
Showing
14 changed files
with
1,948 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
| ||
Script started on 2019-03-07 08:48:35+0530 | ||
#]0;ramkaushik@ram-kaushik: ~/Documents/College/OS-Lab/Ex10##[01;32mramkaushik@ram-kaushik#[00m:#[01;34m~/Documents/College/OS-Lab/Ex10#[00m$ cat sample.c | ||
#include<pthread.h> | ||
#include<stdio.h> | ||
#include<string.h> | ||
#include<stdlib.h> | ||
int sum; | ||
void *runner(void *param); | ||
int main(int argc, char *argv[]) { | ||
pthread_t tid; | ||
pthread_attr_t attr; | ||
if (argc != 2){ | ||
fprintf(stderr,"usage: sample <integer value>\n"); | ||
return -1; | ||
} | ||
if (atoi(argv[1]) < 0){ | ||
fprintf(stderr,"%d must be >= 0 \n",atoi(argv[1])); | ||
return -1; | ||
} | ||
pthread_attr_init(&attr); | ||
pthread_create(&tid,&attr,runner,argv[1]); | ||
pthread_join(tid,NULL); | ||
printf("sum = %d\n",sum); | ||
} | ||
void *runner(void *param) { | ||
int i, upper = atoi(param); | ||
sum = 0; | ||
for (i = 1; i <= upper; i++) | ||
sum += i; | ||
pthread_exit(0); | ||
} | ||
#]0;ramkaushik@ram-kaushik: ~/Documents/College/OS-Lab/Ex10##[01;32mramkaushik@ram-kaushik#[00m:#[01;34m~/Documents/College/OS-Lab/Ex10#[00m$ ./sample 5 | ||
sum = 15 | ||
#]0;ramkaushik@ram-kaushik: ~/Documents/College/OS-Lab/Ex10##[01;32mramkaushik@ram-kaushik#[00m:#[01;34m~/Documents/College/OS-Lab/Ex10#[00m$ cat minmaxavg.c | ||
#include<pthread.h> | ||
#include<stdio.h> | ||
#include<string.h> | ||
#include<stdlib.h> | ||
int max, min, l; | ||
float avg; | ||
int list[10]; | ||
void *Max(void *param); | ||
void *Min(void *param); | ||
void *Avg(void *param); | ||
int main(int argc, char *argv[]) { | ||
pthread_t tid1, tid2, tid3; | ||
pthread_attr_t attr1, attr2, attr3; | ||
if (argc < 2) { | ||
fprintf(stderr,"Usage: Enter list of integer values\n"); | ||
return -1; | ||
} | ||
for(int i = 1; i < argc; i++) | ||
list[i-1] = atoi(argv[i]); | ||
l = argc - 1; | ||
pthread_attr_init(&attr1); | ||
pthread_attr_init(&attr2); | ||
|
||
|
||
pthread_attr_init(&attr3); | ||
pthread_create(&tid1,&attr1,Max, list); | ||
pthread_create(&tid2,&attr2,Min, list); | ||
pthread_create(&tid3,&attr3,Avg, list); | ||
pthread_join(tid1,NULL); | ||
pthread_join(tid2,NULL); | ||
pthread_join(tid3,NULL); | ||
printf("Max, Min, Avg: %d, %d, %f\n",max,min,avg); | ||
} | ||
void *Max(void *param){ | ||
max = list[0]; | ||
for(int i = 1; i < l; i++) | ||
if(max < list[i]) | ||
max = list[i]; | ||
pthread_exit(0); | ||
} | ||
void *Min(void *param){ | ||
min = list[0]; | ||
for(int i = 1; i < l; i++) | ||
if(min > list[i]) | ||
min = list[i]; | ||
pthread_exit(0); | ||
} | ||
void *Avg(void *param){ | ||
avg = 0; | ||
for(int i = 0; i < l; i++) | ||
avg += list[i]; | ||
avg /= l; | ||
pthread_exit(0); | ||
} | ||
#]0;ramkaushik@ram-kaushik: ~/Documents/College/OS-Lab/Ex10##[01;32mramkaushik@ram-kaushik#[00m:#[01;34m~/Documents/College/OS-Lab/Ex10#[00m$ ./minmaxavg 10 30 40 20 | ||
Max, Min, Avg: 40, 10, 25.000000 | ||
#]0;ramkaushik@ram-kaushik: ~/Documents/College/OS-Lab/Ex10##[01;32mramkaushik@ram-kaushik#[00m:#[01;34m~/Documents/College/OS-Lab/Ex10#[00m$ exit | ||
exit | ||
|
||
Script done on 2019-03-07 08:49:16+0530 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include<pthread.h> | ||
#include<stdio.h> | ||
#include<string.h> | ||
#include<stdlib.h> | ||
int max, min, l; | ||
float avg; | ||
int list[10]; | ||
void *Max(void *param); | ||
void *Min(void *param); | ||
void *Avg(void *param); | ||
int main(int argc, char *argv[]) { | ||
pthread_t tid1, tid2, tid3; | ||
pthread_attr_t attr1, attr2, attr3; | ||
if (argc < 2) { | ||
fprintf(stderr,"Usage: Enter list of integer values\n"); | ||
return -1; | ||
} | ||
for(int i = 1; i < argc; i++) | ||
list[i-1] = atoi(argv[i]); | ||
l = argc - 1; | ||
pthread_attr_init(&attr1); | ||
pthread_attr_init(&attr2); | ||
pthread_attr_init(&attr3); | ||
pthread_create(&tid1,&attr1,Max, list); | ||
pthread_create(&tid2,&attr2,Min, list); | ||
pthread_create(&tid3,&attr3,Avg, list); | ||
pthread_join(tid1,NULL); | ||
pthread_join(tid2,NULL); | ||
pthread_join(tid3,NULL); | ||
printf("Max, Min, Avg: %d, %d, %f\n",max,min,avg); | ||
} | ||
void *Max(void *param){ | ||
max = list[0]; | ||
for(int i = 1; i < l; i++) | ||
if(max < list[i]) | ||
max = list[i]; | ||
pthread_exit(0); | ||
} | ||
void *Min(void *param){ | ||
min = list[0]; | ||
for(int i = 1; i < l; i++) | ||
if(min > list[i]) | ||
min = list[i]; | ||
pthread_exit(0); | ||
} | ||
void *Avg(void *param){ | ||
avg = 0; | ||
for(int i = 0; i < l; i++) | ||
avg += list[i]; | ||
avg /= l; | ||
pthread_exit(0); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include<pthread.h> | ||
#include<stdio.h> | ||
#include<string.h> | ||
#include<stdlib.h> | ||
int sum; | ||
void *runner(void *param); | ||
int main(int argc, char *argv[]) { | ||
pthread_t tid; | ||
pthread_attr_t attr; | ||
if (argc != 2){ | ||
fprintf(stderr,"usage: sample <integer value>\n"); | ||
return -1; | ||
} | ||
if (atoi(argv[1]) < 0){ | ||
fprintf(stderr,"%d must be >= 0 \n",atoi(argv[1])); | ||
return -1; | ||
} | ||
pthread_attr_init(&attr); | ||
pthread_create(&tid,&attr,runner,argv[1]); | ||
pthread_join(tid,NULL); | ||
printf("sum = %d\n",sum); | ||
} | ||
void *runner(void *param) { | ||
int i, upper = atoi(param); | ||
sum = 0; | ||
for (i = 1; i <= upper; i++) | ||
sum += i; | ||
pthread_exit(0); | ||
} |
Oops, something went wrong.