Skip to content

Instantly share code, notes, and snippets.

@mariuz
Created May 27, 2009 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariuz/118523 to your computer and use it in GitHub Desktop.
Save mariuz/118523 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include<stdlib.h>
#include <sys/ipc.h>
#include <sys/types.h>
#include"functii.h"
int main()
{
pid_t PID1=PID();
struct shmid_ds buff;
key_t key;
int shmid;
int *p;
printf("Procesul inainte de fork %d\n",PID1);
printf("\n");
if((key = ftok())==-1)
{
perror("ftok");
return -1;
}
if((shmid=shmget(key,4*sizeof(char),IPC_CREAT))==-1)
{
return -1;
}
if((p=(int *)shmat(shmid,NULL,0))==(void *)-1)
{
perror("shmat");
return -1;
}
PID1=fork();
switch(PID1){
case -1:
printf("Erroare!");
return EXIT_FAILURE;
case 0: //fiu
printf("Procesul fiu %d\n",PID());
p=getpid();
sleep(50);
break;
default: //tata
sleep(60);
printf("Procesul toto %d\n si fiul %d\n",PID(),PID1);
kill(*p,9);
break;
}
shmdt(p);
shmctl(shmid,IPC_RMID,&buff);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment