Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- int znajdz(int * tab, int tabnumb){
- int i = 0;
- while(i<tabnumb && tab[i] == -1)
- i++;
- if ( i == tabnumb)
- return -1;
- return i;
- }
- int main(int argc, char* argv[]){
- int tab[100];
- int tabnumb = argc - 1;
- int i,j;
- int pid;
- int procnumb;
- int mothership = 1;
- for(i=1;i<argc;i++){
- tab[i-1] = atoi(argv[i]);
- tab[i] = -1;
- }
- procnumb = tab[0];
- tab[0] = -1;
- i = 0;
- while(i < procnumb){
- if(procnumb > 0)
- pid = fork();
- if(pid == 0){
- i = 0;
- j = znajdz(tab, tabnumb);
- if(j== -1)
- procnumb = -1;
- else{
- procnumb = tab[j];
- tab[j] = -1;
- }
- mothership = 0;
- }
- else{
- i++;
- }
- }
- if(mothership == 1){
- sleep(1);
- eprocnumbeclp( "ps", "-u student", "--forest", NULL );
- }else
- sleep(5);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement