-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultishell.c
More file actions
60 lines (52 loc) · 1.14 KB
/
multishell.c
File metadata and controls
60 lines (52 loc) · 1.14 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
/**
*
*/
#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>
/* these should be the same as multishell.c */
#define MY_FILE_SIZE 1024
#define MY_SHARED_FILE_NAME "/sharedlogfile"
#define MAX_SHELL 10
#define DEFAULT_NSHELL 2
char *addr = NULL; /*mmap addres*/
int fd = -1; /*fd for shared file object*/
int initmem()
{
fd = shm_open(MY_SHARED_FILE_NAME,
O_CREAT | O_RDWR | O_TRUNC, 0666);
if (fd < 0){
perror("multishell.c:open file:");
exit(1);
}
if (ftruncate(fd, 1024) == -1){
perror("ftruncate");
exit(1);
}
addr = mmap(NULL, MY_FILE_SIZE,
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (addr == NULL){
perror("mmap:");
exit(1);
}
return 0;
}
/**
* todo, you can create multiple function, variables, etc..
* */
int main(int argc, char **argv)
{
initmem();
/*unlink mmap*/
munmap(addr, 1024);
/* close the shared memory file*/
close(fd);
return 0;
}