I have to do program in C on linux, that can control mplayer using mknod() function.
When I run mplayer by this command
mplayer -input file=/tmp/film spiderman.ts
I want to control that with my C program just like with the echo function
echo "pause" >> /tmp/film
This is my code :
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <signal.h>
#include <unistd.h>
int main(int argc, char* argv[]){
    int fdes,res;
    char x;
    /*commands*/
    char msg1[] = "pause\n";
    char msg2[] = "quit\n";
     /*creating fifo file*/
    unlink("/tmp/film");
    res=mknod("/tmp/film", S_IFIFO|0666, 0);
    if (res<0) perror("error_creating_fifo");
    fdes = open("/tmp/film", O_WRONLY);
    if (fdes<0) perror("error_open_fifo");
    while(1)
    {
        printf("Enter command\n");
        x = getchar();
        getchar();//dont take enter character
        switch(x)
        {
            case 'p': 
                printf("PAUSE\n");
                write(fdes, msg1, sizeof(msg1));
                break;
            case 'q': 
                printf("QUIT\n");
                write(fdes, msg2, sizeof(msg2));
                break;
            default:
                printf("Unknown command");
                break;
        }
    }
    close(fdes);
    return 0;
}
The problem is, it works only once. I can't for example pause and then unpause the movie.
                        
Closing and reopening the pipe for each command did the trick for me: