https://docs.google.com/document/d/1CEpW5HkQDwMgBL196NcCPeC8yQMzGWKO1Obvexx4H_M/edit
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#define MAX_COUNT 200
#define BUF_SIZE 100
void main(void){
pid_t pid;
int i;
char buf[BUF_SIZE];
fork();
pid = getpid();
for(i=1; i <= MAX_COUNT; i++){
sprintf(buf, "This line is from pid %D, value = %dn", pid, i);
write(1, buf, strlen(buf));
}
}
#include <stdio.h>
#include <sys/types.h>
#define MAX_COUNT 5
void ChildProcess(void);
void ParentProcess(void);
int x=5; int y=6; int z;
void main(void){
pid_t pid;
pid = fork();
if(pid==0){
ChildProcess();
} else {
ParentProcess();
}
}
void ChildProcess(void){
int i;
for(i=1; i<= MAX_COUNT; i++) printf("This line is from child, value = %dn", i);
printf(" *** child process is done *** n"); z=x+y;
}
void ParentProcess(void){
int i;
for(i=1; i<= MAX_COUNT; i++) printf("This line is from parent, value = %dn", i);
printf(" *** parent process is done *** n"); printf("z erteke: %dn", z);
}
#include <sys/types.h> // forkhoz
#include <unistd.h>
#include <string.h>
#include <wait.h>
int main(){
int l;
pid_t child=fork();
if(child<0){
perror("hiba");
} else {
if(child>0){
//wait(&i);
while(waitpid(child, &l, WNOHANG)==0){
printf("Meg varok a gyerekekren");
sleep(1);
}
printf("%st pid-szam: %in", "szulo ", getpid());
} else {
sleep(5);
printf("%st pid-szam: %in", "Gyerek ",getpid());
};
};
}