-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingleshell.c
More file actions
52 lines (47 loc) · 995 Bytes
/
singleshell.c
File metadata and controls
52 lines (47 loc) · 995 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
/**
* header
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <string.h>
#define INBUF_SIZE 256
/* these should be the same as multishell.c */
#define MY_FILE_SIZE 1024
#define MY_SHARED_FILE_NAME "/sharedlogfile"
char *addr = NULL;
int fd = -1;
int initmem()
{
fd = shm_open(MY_SHARED_FILE_NAME, O_RDWR, 0);
if (fd < 0){
perror("singleshell.c:fd:line31");
exit(1);
}
addr = mmap(NULL, MY_FILE_SIZE,
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (addr == NULL){
perror("singleshell.c:mmap:");
close(fd);
exit(1);
}
return 0;
}
/**
* todo: you can start with myshellv3.c from lecture notes
*/
int main(int argc, char *argv[])
{
initmem();
// Unmap the shared memory
munmap(addr, 1024);
// Close the shared memory file
close(fd);
}