test_fifo.c 1.14 KB
Newer Older
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
// C program to implement one side of FIFO 
// This side writes first, then reads 
#include <stdio.h> 
#include <string.h> 
#include <fcntl.h> 
#include <sys/stat.h> 
#include <sys/types.h> 
#include <unistd.h> 
  
int main() 
{ 
    int fd; 
  
    // FIFO file path 
    char * myfifo = "/tmp/myfifo"; 
  
    // Creating the named file(FIFO) 
    // mkfifo(<pathname>, <permission>) 
    mkfifo(myfifo, 0666); 
  
    char arr1[80], arr2[80]; 
    //while (1) 
    //{ 
        // Open FIFO for write only 
        fd = open(myfifo, O_WRONLY);
        printf("FD is: %d\n", fd); 
  
        // Take an input arr2ing from user. 
        // 80 is maximum length 
        //fgets(arr2, 80, stdin); 
  
        // Write the input arr2ing on FIFO 
        // and close it 
        char * msg = "api body_leds(255,255,255)\n";
 
        write(fd, msg, strlen(msg)+1); 
        close(fd); 
  
        // Open FIFO for Read only 
        //fd = open(myfifo, O_RDONLY); 
  
        // Read from FIFO 
        //read(fd, arr1, sizeof(arr1)); 
  
        // Print the read message 
        //printf("User2: %s\n", arr1); 
        //close(fd); 
    //} 
    return 0; 
}