Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/resource.h>
- #include <sys/time.h>
- int main(int argc , char *argv[])
- {
- pid_t pid, ppid;
- int status;
- struct rusage rusage;
- unsigned long czas1, czas2;
- long suma, i, procesy;
- printf("Liczba procesów to %s \n", argv[1]);
- procesy = atoi(argv[1]);
- /*
- if ((pid = fork()) == -1)
- {
- perror("Blad fork");
- exit(1);
- }
- */
- printf ( " proces macierzysty to %d \n", getpid());
- ppid = getpid();
- for ( int a = 0 ; a < procesy ; a++)
- {
- if (fork() == 0)
- {
- pid = getpid();
- printf("Proces potomny: PID = %d\n", pid);
- printf("Proces macierzysty: PID = %d\n", getppid());
- for (i=0; i<400000; i++)
- {
- suma+=i*3+5;
- pid = getpid();
- }
- printf("kod wyjscia to %d\n",a + 8 );
- exit((a + 8));
- }
- else
- {
- //pid = fork();
- //pid = getpid();
- printf("Proces macierzysty: PID = %d\n", pid);
- if (wait3(&status, 0, &rusage) == -1)
- {
- perror("Blad wait3");
- exit(1);
- }
- czas1 = (rusage.ru_utime).tv_sec*1000 + (rusage.ru_utime).tv_usec/1000;
- czas2 = (rusage.ru_stime).tv_sec*1000 + (rusage.ru_stime).tv_usec/1000;
- printf("Czas wykonania potomka\n");
- printf("\t- w trybie u�ytkownika: %ld ms\n", czas1);
- printf("\t- w trybie j�dra: %ld ms\n", czas2);
- printf("Kod wyjścia to %d \n", ( status >> 8));
- //exit(0);
- }
- }
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement