Old stuff/ecole_etude_fac_de_pau/licence_3/systeme-d-exploitation/tp4/exo2.c~
(Deskargatu)
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
void fonction(int n)
{
char* test;
key_t cle= ftok("./prout",0);
int id;
id = shmget(cle,0,0);
if (id == -1)
{
perror("shmget");
exit(-1);
}
// printf("Id = %d\n",id);
test = (char*)shmat(id,0, 0);
printf("On lit %s\n",test);
shmdt(test);
exit(-1);
}
int main(int argc, char** argv)
{
pid_t pid;
char* test=NULL;
key_t cle= ftok("./prout",0);
int id;
const char source[] = "salut";
id = shmget(cle,100*sizeof(char),IPC_CREAT|IPC_EXCL|0777);
if (id == -1)
{
perror("shmget");
exit(-1);
}
// printf("Id = %d\n",id);
test = (char*)shmat(id,0, 0);
if ((int)test == -1) { perror("error shmat"); exit(-1); }
// printf("Adresse %d\n",test);
while(1)
{
fgets(test,100,stdin);
printf("On ecrit : %s\n",test);
// printf("Adresse %d\n",test);
printf("On lit : %s\n",test);
}
// shmdt(test);
//shmctl(id, IPC_RMID, NULL);
return 1;
}