I have a part of code which is written to write into pipe from native code in Android. However, the program does not seem to block on the write operation. As per my understanding the program should block on write untill there is a process that finally reads from the pipe. Please let me know what is wrong with below code and why it exits without blocking.
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <unistd.h>
int main()
{
const char* PATH = "/data/data/com.endpoint.login/v_pipe8";
char* line = "Hello Pipe!";
int pipe;
mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
pipe = mkfifo(PATH, mode);
if (pipe == -1)
{
printf("mkfifo failure\n");
}
sleep(1);
int err = write(pipe,line,strlen(line));
if (err == -1)
{
printf("write error in the pipe\n");
}
close(pipe);
return 0;
}