fork download
  1. #include<stdio.h>
  2. #include<sys/ipc.h>
  3. #include<sys/shm.h>
  4. #include<string.h>
  5. int main(){
  6. key_t key=ftok("shmfile",65);
  7. int shmid=shmget(key, 1024, 0666 | IPC_CREAT);
  8. char*str=(char*) shmat(shmid, NULL,0);
  9. strcpy(str, "Hello fom the server!");
  10. printf("Server: Data written to shared memory. \n");
  11. shmdt(str);
  12. return 0;
  13. }
Success #stdin #stdout 0.04s 25876KB
stdin
Standard input is empty
stdout
#include<stdio.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<string.h>
int main(){
key_t key=ftok("shmfile",65);
int shmid=shmget(key, 1024, 0666 | IPC_CREAT);
char*str=(char*) shmat(shmid, NULL,0);
strcpy(str, "Hello fom the server!");
printf("Server: Data written to shared memory. \n");
shmdt(str);
return 0;
}