top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

OS: Difference between formatted piping and low level piping and when to use what ?

+3 votes
458 views
OS: Difference between formatted piping and low level piping and when to use what ?
posted Feb 27, 2016 by Harshita

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

popen() -- Formatted Piping

FILE *popen(char *command, char *type) -- opens a pipe for I/O where the command is the process that will be connected to the calling process thus creating the pipe. The type is either "r" - for reading, or "w" for writing.
popen() returns is a stream pointer or NULL for any errors.
A pipe opened by popen() should always be closed by pclose(FILE *stream).
We use fprintf() and fscanf() to communicate with the pipe's stream.

pipe() -- Low level Piping

int pipe(int fd[2]) -- creates a pipe and returns two file descriptors, fd[0], fd[1]. fd[0] is opened for reading, fd[1] for writing.
pipe() returns 0 on success, -1 on failure and sets errno accordingly.
The standard programming model is that after the pipe has been set up, two (or more) cooperative processes will be created by a fork and data will be passed using read() and write().
Pipes opened with pipe() should be closed with close(int fd).

answer Mar 11, 2016 by Manikandan J
...