Created
May 27, 2009 08:28
-
-
Save mariuz/118523 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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