-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsender.c
More file actions
53 lines (39 loc) · 866 Bytes
/
sender.c
File metadata and controls
53 lines (39 loc) · 866 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//sender.c
#include "common.h"
#include <stdio.h>
//key
key_t key;
//UNSAFE CODE
//shared memory
int shmid;
char * shmptr;
char input[SHM_SIZE];
//semaphore
sem_t * full;
sem_t * mutex;
//semaphore
void Init()
{
key = KEY_NUM; //init key
shmid = GetShmId(key); // init shared memory
shmptr = shmat(shmid,NULL,0); // attach segement to vitural ...?
//semaphore init
full = sem_open(FULL_NAME,O_CREAT);
mutex = sem_open(MUTEX_NAME,O_CREAT);
}
void SaveMessage()
{
P(mutex);
strcpy(shmptr,input);
V(mutex);
V(full);
}
int main(int argc, char const *argv[])
{
Init();
/*waiting for user to input message*/
fgets(input, 1024, stdin); //input message from shell
SaveMessage();
printf("Sender: Process End\n");
return 0;
}