-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemclient.c
More file actions
64 lines (50 loc) · 1.04 KB
/
memclient.c
File metadata and controls
64 lines (50 loc) · 1.04 KB
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
54
55
56
57
58
59
60
61
62
63
64
/*
* Memdisk client
*
* Ilias K. Kasmeridis, 2018
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <unistd.h>
#include "sharedmem.h"
shmem_t *shared_mem;
int main(int argc, char *argv[])
{
int i;
if (argc < 2)
{
printf("Syntax: %s <command> [args...]\n");
return 0;
}
shared_mem = (shmem_t*) sh_get();
sh_lock();
shared_mem->nargs = argc - 2;
for (i = 0; i < shared_mem->nargs; i++)
{
strcpy(shared_mem->args[i], argv[2+i]);
}
strcpy(shared_mem->command, argv[1]);
sh_signal();
while (1)
{
if (strcmp(argv[1], "exit") == 0)
break;
while (shared_mem->haveread == 1)
sh_wait();
if (strcmp(shared_mem->response, ""))
printf("%s", shared_mem->response);
shared_mem->haveread = 1;
sh_signal();
if (shared_mem->endofcmd)
break;
}
sh_unlock();
sh_detach();
return 0;
}