-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstud_send.c
More file actions
37 lines (29 loc) · 757 Bytes
/
stud_send.c
File metadata and controls
37 lines (29 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/shm.h>
typedef struct student{
int roll;
int marks;
}student;
int main() {
int i, n;
// ftok to generate unique key
key_t key = ftok("shmfile",65);
// shmget returns an identifier in shmid
int shmid = shmget(key,1024,0666|IPC_CREAT);
// shmat to attach to shared memory
//char *str = (char*) shmat(shmid,(void*)0,0);
student *stud = (student*) shmat(shmid,(void*)0,0);
printf("Input the no of children :");
scanf("%d", &n);
for(i=0;i<n;i++)
{
stud[i].roll=i+1;
printf("\nInput the marks of student %d: ",i+1);
scanf("%d",&stud[i].marks);
}
stud[i].roll=-1;
stud[i].marks=-1;
shmdt(stud);
return 0;
}