#include <stdio.h>

#include <stdlib.h>

#include <sys/ipc.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <sys/shm.h>

#include <sys/wait.h>

#include <unistd.h>





void Collaz ( int * num ){


do{

printf("%d ",*num);

if((*num) %2 == 1) {

*num = 3*(*num) +1;

}else{

*num /= 2;

}

}while(*num != 1);

}




int main (){


// Shared Memory segment id

int segment_id;

// Shared Memory segment pointer

int * shared_memory;

// size

const int size =32;

// pid

int pid;


// allocate shared memory & attach

segment_id = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);

shared_memory = (int *) shmat(segment_id,NULL,0);


scanf("%d",shared_memory);


pid = fork();


if (pid <0) {

fprintf(stderr,"Fork Failed");

return 1;

}else if(pid ==0){

printf("child\n");

Collaz(shared_memory);

}else{

wait(NULL);

printf("Child Complete");

}


}


존나좆같네