Az oldal töltődik…

https://docs.google.com/document/d/1CEpW5HkQDwMgBL196NcCPeC8yQMzGWKO1Obvexx4H_M/edit

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <sys/types.h>
  4.  
  5. #define MAX_COUNT 200
  6. #define BUF_SIZE 100
  7.  
  8. void main(void){
  9.     pid_t pid;
  10.     int i;
  11.     char buf[BUF_SIZE];
  12.     fork();
  13.     pid = getpid();
  14.     for(i=1; i <= MAX_COUNT; i++){
  15.    	 sprintf(buf, "This line is from pid %D, value = %dn", pid, i);
  16.    	 write(1, buf, strlen(buf));
  17.     }
  18. }

  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #define MAX_COUNT 5
  4.  
  5. void ChildProcess(void);
  6. void ParentProcess(void);
  7. int x=5; int y=6; int z;
  8.  
  9. void main(void){
  10.     pid_t pid;
  11.     pid = fork();
  12.     if(pid==0){
  13.    	 ChildProcess();
  14.     } else {
  15.    	 ParentProcess();
  16.     }
  17.  
  18. }
  19.  
  20. void ChildProcess(void){
  21.     int i;
  22.     for(i=1; i<= MAX_COUNT; i++) printf("This line is from child, value = %dn", i);
  23.     printf(" *** child process is done *** n"); z=x+y;
  24. }
  25. void ParentProcess(void){
  26.     int i;
  27.     for(i=1; i<= MAX_COUNT; i++) printf("This line is from parent, value = %dn", i);
  28.     printf(" *** parent process is done *** n"); printf("z erteke: %dn", z);
  29.  
  30. }
  1. #include <sys/types.h> // forkhoz
  2. #include <unistd.h>
  3. #include <string.h>
  4. #include <wait.h>
  5.  
  6. int main(){
  7.     int l;
  8.     pid_t child=fork();
  9.     if(child<0){
  10.    	 perror("hiba");
  11.     } else {
  12.    	 if(child>0){
  13.    		 //wait(&i);
  14.    		 while(waitpid(child, &l, WNOHANG)==0){
  15.    			 printf("Meg varok a gyerekekren");
  16.    			 sleep(1);
  17.    		 }
  18.    		 printf("%st pid-szam: %in", "szulo ", getpid());
  19.    	 } else {
  20.    		 sleep(5);
  21.    		 printf("%st pid-szam: %in", "Gyerek ",getpid());
  22.    	 };
  23.     };
  24. }

Leave a Reply