What are named pipes?

后端 未结 10 959
无人共我
无人共我 2020-11-27 10:08

What are they and how do they work?

Context happens to be SQL Server

相关标签:
10条回答
  • 2020-11-27 11:08

    Compare

    echo "test" | wc
    

    to

    mkdnod apipe p
    wc apipe
    

    wc will block until

    echo "test" > apipe
    

    executes

    0 讨论(0)
  • 2020-11-27 11:09

    Pipes are a way of streaming data between applications. Under Linux I use this all the time to stream the output of one process into another. This is anonymous because the destination app has no idea where that input-stream comes from. It doesn't need to.

    A named pipe is just a way of actively hooking onto an existing pipe and hoovering-up its data. It's for situations where the provider doesn't know what clients will be eating the data.

    0 讨论(0)
  • 2020-11-27 11:10

    Linux Pipes
    First In First Out (FIFO) interproccess communication mechanism.

    Unnamed Pipes
    On the command line, represented by a "|" between two commands.

    Named Pipes
    A FIFO special file. Once created, you can use the pipe just like a normal file(open, close, write, read, etc).

    To create a named pipe, called "myPipe", from the command line (man page):

    mkfifo myPipe  
    

    To create a named pipe from c, where "pathname" is the name you would like the pipe to have and "mode" contains the permissions you want the pipe to have (man page):

    #include <sys/types.h>
    #include <sys/stat.h>
    int mkfifo(const char *pathname, mode_t mode);
    
    0 讨论(0)
  • 2020-11-27 11:13

    Both on Windows and POSIX systems, named-pipes provide a way for inter-process communication to occur among processes running on the same machine. What named pipes give you is a way to send your data without having the performance penalty of involving the network stack.

    Just like you have a server listening to a IP address/port for incoming requests, a server can also set up a named pipe which can listen for requests. In either cases, the client process (or the DB access library) must know the specific address (or pipe name) to send the request. Often, a commonly used standard default exists (much like port 80 for HTTP, SQL server uses port 1433 in TCP/IP; \\.\pipe\sql\query for a named pipe).

    By setting up additional named pipes, you can have multiple DB servers running, each with its own request listeners.

    The advantage of named pipes is that it is usually much faster, and frees up network stack resources.

    -- BTW, in the Windows world, you can also have named pipes to remote machines -- but in that case, the named pipe is transported over TCP/IP, so you will lose performance. Use named pipes for local machine communication.

    0 讨论(0)
提交回复
热议问题