Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <math.h>
- #include <time.h>
- #include <sys/time.h>
- void obciaz(int new_nice) {
- nice(new_nice);
- int a;
- for(int i=0; i<1000000000; i++) {
- a = i*i*i*i;
- sin(13.254f);
- }
- }
- int main(int argc, char **argv) {
- for(int i=1; i<argc; i++) {
- int new_nice = atoi(argv[i]);
- int pid;
- if((pid = fork()) == 0) {
- struct timeval tv1, tv2;
- gettimeofday(&tv1, NULL);
- obciaz(new_nice);
- gettimeofday(&tv2, NULL);
- printf("Total time for process of nice %d = %f seconds\n", new_nice,
- (double) (tv2.tv_usec - tv1.tv_usec) / 1000000 +
- (double) (tv2.tv_sec - tv1.tv_sec));
- exit(0);
- }
- }
- int status;
- for(int i=1; i<argc; i++) {
- wait(&status);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement