Кіріспе
Unix-ке ұқсас компьютерлік операциялық жүйелерде құбыр желісі – процестер арасындағы байланыс механизмі, хабар алмасу арқылы жұмыс істейді. Құбыр желісі – стандартты ағындары арқылы тізбектелген процестер жиынтығы, сондықтан әрбір процестің шығыс мәтіні (stdout) тікелей келесі процестің кірісі (stdin) ретінде беріледі. Екінші процесс бірінші процесс әлі орындалып жатқанда басталады және олар бір уақытта орындалады. Құбырлар тұжырымдамасын Unix-тің алғашқы даму ортасы – Bell Labs-те, Unix әзірленген кезде Дуглас Макилрой қолдады, бұл оның құралдар жинағының философиясын қалыптастырды. Ол физикалық құбырға ұқсастығымен аталған. Осы құбырлардың маңызды ерекшелігі – «ішкі құрылымды жасыру» (Ritchie & Thompson, 1974). Бұл жүйеде түсініктілік пен қарапайымдылықты арттырады. Бұл мақала анонимді құбырлар туралы, онда бір процесс жазған деректер келесі процесс оқығанға дейін операциялық жүйеде сақталады, ал процестер аяқталғаннан кейін бұл бір бағытты канал жоғалады. Бұл атаулы құбырлардан өзгеше, онда хабарламалар файл ретінде белгіленген құбырға немесе одан жіберіледі және процестер аяқталғаннан кейін де сақталады. Анонимді құбырлардың стандартты қабықша синтаксисі – тік сызықтармен («|») бөлінген бірнеше команданы тізімдеу:
the original implementation for shells
In Unix like computer operating systems, a pipeline is a mechanism for inter process communication using message passing. A pipeline is a set of processes chained together by their standard streams, so that the output text of each process (stdout) is passed directly as input (stdin) to the next one. The second process is started as the first process is still executing, and they are executed concurrently. The concept of pipelines was championed by Douglas McIlroy at Unix's ancestral home of Bell Labs, during the development of Unix, shaping its toolbox philosophy. It is named by analogy to a physical pipeline. A key feature of these pipelines is their "hiding of internals" (Ritchie & Thompson, 1974). This in turn allows for more clarity and simplicity in the system. This article is about anonymous pipes, where data written by one process is buffered by the operating system until it is read by the next process, and this uni directional channel disappears when the processes are completed. This differs from named pipes, where messages are passed to or from a pipe that is named by making it a file, and remains after the processes are completed. The standard shell syntax for anonymous pipes is to list multiple commands, separated by vertical bars ("pipes" in common Unix verbiage):
command1 | command2 | command3
For example, to list files in the current directory , retain only the lines of output containing the string , and view the result in a scrolling page , a user types the following into the command line of a terminal:
ls l | grep key | less
The command ls l is executed as a process, the output (stdout) of which is piped to the input (stdin) of the process for grep key; and likewise for the process for less. Each process takes input from the previous process and produces output for the next process via standard streams. Each | tells the shell to connect the standard output of the command on the left to the standard input of the command on the right by an inter process communication mechanism called an (anonymous) pipe, implemented in the operating system. Pipes are unidirectional; data flows through the pipeline from left to right.
command1 | command2 | command3
the original implementation for shells
In Unix like computer operating systems, a pipeline is a mechanism for inter process communication using message passing. A pipeline is a set of processes chained together by their standard streams, so that the output text of each process (stdout) is passed directly as input (stdin) to the next one. The second process is started as the first process is still executing, and they are executed concurrently. The concept of pipelines was championed by Douglas McIlroy at Unix's ancestral home of Bell Labs, during the development of Unix, shaping its toolbox philosophy. It is named by analogy to a physical pipeline. A key feature of these pipelines is their "hiding of internals" (Ritchie & Thompson, 1974). This in turn allows for more clarity and simplicity in the system. This article is about anonymous pipes, where data written by one process is buffered by the operating system until it is read by the next process, and this uni directional channel disappears when the processes are completed. This differs from named pipes, where messages are passed to or from a pipe that is named by making it a file, and remains after the processes are completed. The standard shell syntax for anonymous pipes is to list multiple commands, separated by vertical bars ("pipes" in common Unix verbiage):
command1 | command2 | command3
For example, to list files in the current directory , retain only the lines of output containing the string , and view the result in a scrolling page , a user types the following into the command line of a terminal:
ls l | grep key | less
The command ls l is executed as a process, the output (stdout) of which is piped to the input (stdin) of the process for grep key; and likewise for the process for less. Each process takes input from the previous process and produces output for the next process via standard streams. Each | tells the shell to connect the standard output of the command on the left to the standard input of the command on the right by an inter process communication mechanism called an (anonymous) pipe, implemented in the operating system. Pipes are unidirectional; data flows through the pipeline from left to right.
Мысалы, ағымдағы каталогтағы файлдарды тізімдеу үшін, тек белгілі бір жолдарды қамтитын шығыс жолдарын сақтап, нәтижені бет-беттен қарау үшін пайдаланушы терминалдың командалық жолына келесіні жазады:
the original implementation for shells
In Unix like computer operating systems, a pipeline is a mechanism for inter process communication using message passing. A pipeline is a set of processes chained together by their standard streams, so that the output text of each process (stdout) is passed directly as input (stdin) to the next one. The second process is started as the first process is still executing, and they are executed concurrently. The concept of pipelines was championed by Douglas McIlroy at Unix's ancestral home of Bell Labs, during the development of Unix, shaping its toolbox philosophy. It is named by analogy to a physical pipeline. A key feature of these pipelines is their "hiding of internals" (Ritchie & Thompson, 1974). This in turn allows for more clarity and simplicity in the system. This article is about anonymous pipes, where data written by one process is buffered by the operating system until it is read by the next process, and this uni directional channel disappears when the processes are completed. This differs from named pipes, where messages are passed to or from a pipe that is named by making it a file, and remains after the processes are completed. The standard shell syntax for anonymous pipes is to list multiple commands, separated by vertical bars ("pipes" in common Unix verbiage):
command1 | command2 | command3
For example, to list files in the current directory , retain only the lines of output containing the string , and view the result in a scrolling page , a user types the following into the command line of a terminal:
ls l | grep key | less
The command ls l is executed as a process, the output (stdout) of which is piped to the input (stdin) of the process for grep key; and likewise for the process for less. Each process takes input from the previous process and produces output for the next process via standard streams. Each | tells the shell to connect the standard output of the command on the left to the standard input of the command on the right by an inter process communication mechanism called an (anonymous) pipe, implemented in the operating system. Pipes are unidirectional; data flows through the pipeline from left to right.
ls -l | grep key | less
the original implementation for shells
In Unix like computer operating systems, a pipeline is a mechanism for inter process communication using message passing. A pipeline is a set of processes chained together by their standard streams, so that the output text of each process (stdout) is passed directly as input (stdin) to the next one. The second process is started as the first process is still executing, and they are executed concurrently. The concept of pipelines was championed by Douglas McIlroy at Unix's ancestral home of Bell Labs, during the development of Unix, shaping its toolbox philosophy. It is named by analogy to a physical pipeline. A key feature of these pipelines is their "hiding of internals" (Ritchie & Thompson, 1974). This in turn allows for more clarity and simplicity in the system. This article is about anonymous pipes, where data written by one process is buffered by the operating system until it is read by the next process, and this uni directional channel disappears when the processes are completed. This differs from named pipes, where messages are passed to or from a pipe that is named by making it a file, and remains after the processes are completed. The standard shell syntax for anonymous pipes is to list multiple commands, separated by vertical bars ("pipes" in common Unix verbiage):
command1 | command2 | command3
For example, to list files in the current directory , retain only the lines of output containing the string , and view the result in a scrolling page , a user types the following into the command line of a terminal:
ls l | grep key | less
The command ls l is executed as a process, the output (stdout) of which is piped to the input (stdin) of the process for grep key; and likewise for the process for less. Each process takes input from the previous process and produces output for the next process via standard streams. Each | tells the shell to connect the standard output of the command on the left to the standard input of the command on the right by an inter process communication mechanism called an (anonymous) pipe, implemented in the operating system. Pipes are unidirectional; data flows through the pipeline from left to right.
ls -l командасы процесс ретінде орындалады, оның шығысы (stdout) grep key процесінің кірісіне (stdin) жіберіледі; және сондай-ақ less процесі үшін де осылай. Әрбір процесс алдыңғы процестен кіріс алады және стандартты ағындар арқылы келесі процесске шығыс береді. Әрбір «|» таңбасы қабықшаға сол жақтағы команданың стандартты шығысын операциялық жүйеде іске асырылған (анонимді) құбыр деп аталатын процестер арасындағы байланыс механизмі арқылы оң жақтағы команданың стандартты кірісіне қосуды бұйырады. Құбырлар бір бағытты; деректер құбыр арқылы солдан оңға қарай ағып өтеді.
the original implementation for shells
In Unix like computer operating systems, a pipeline is a mechanism for inter process communication using message passing. A pipeline is a set of processes chained together by their standard streams, so that the output text of each process (stdout) is passed directly as input (stdin) to the next one. The second process is started as the first process is still executing, and they are executed concurrently. The concept of pipelines was championed by Douglas McIlroy at Unix's ancestral home of Bell Labs, during the development of Unix, shaping its toolbox philosophy. It is named by analogy to a physical pipeline. A key feature of these pipelines is their "hiding of internals" (Ritchie & Thompson, 1974). This in turn allows for more clarity and simplicity in the system. This article is about anonymous pipes, where data written by one process is buffered by the operating system until it is read by the next process, and this uni directional channel disappears when the processes are completed. This differs from named pipes, where messages are passed to or from a pipe that is named by making it a file, and remains after the processes are completed. The standard shell syntax for anonymous pipes is to list multiple commands, separated by vertical bars ("pipes" in common Unix verbiage):
command1 | command2 | command3
For example, to list files in the current directory , retain only the lines of output containing the string , and view the result in a scrolling page , a user types the following into the command line of a terminal:
ls l | grep key | less
The command ls l is executed as a process, the output (stdout) of which is piped to the input (stdin) of the process for grep key; and likewise for the process for less. Each process takes input from the previous process and produces output for the next process via standard streams. Each | tells the shell to connect the standard output of the command on the left to the standard input of the command on the right by an inter process communication mechanism called an (anonymous) pipe, implemented in the operating system. Pipes are unidirectional; data flows through the pipeline from left to right.
Командалық желі интерфейстеріндегі құбырлар
Барлық кеңінен қолданылатын Unix қабықшалары құбыржолдар құруға арналған ерекше синтаксистік құрылымға ие. Қолданудың барлық жағдайларында командалар ASCII тік сызық символымен (|) бөлініп, тізбекпен жазылады, осы себепті ол көбінесе "құбыр символы" деп аталады. Қабықша процестерді іске қосып, олардың стандарттық ағындары арасындағы қажетті байланыстарды (кейбір буферлік жадты қоса) қамтамасыз етеді.
Қателер ағыны
Әдетте, құбыржолдағы процестердің стандартты қателік ағындары ("stderr") құбыр арқылы жіберілмейді; оның орнына олар біріктіріліп, консольге бағытталады. Дегенмен, көптеген қабықшаларда осы әрекетті өзгертуге арналған қосымша синтаксис бар. Мысалы, csh қабықшасында |& белгісін | белгісінің орнына пайдалану стандартты қателік ағынының стандартты шығыспен біріктіріліп, келесі процеске берілуін білдіреді. Bash қабықшасы 4.0 нұсқасынан бастап немесе 2>&1 арқылы стандартты қателіктерді біріктіре алады, сондай-ақ оларды басқа файлға қайта бағыттауға болады.
Құбырларды бағдарламалық түрде құру
Құбырлар бағдарламалық басқару арқылы жасалуы мүмкін. Unix құбыр жүйелік шақыруы операциялық жүйеден жаңа анонимді құбыр нысанын жасауды сұрайды. Бұл процесте екі жаңа ашылған файл дескрипторы пайда болады: құбырдың тек оқуға арналған және тек жазуға арналған соңғы нүктелері. Құбырдың соңғы нүктелері қалыпты, анонимді файл дескрипторлары сияқты көрінеді, бірақ оларда іздеу мүмкіндігі жоқ. Тұйыққа түсуден алдын алу және параллелизмді пайдалану үшін, бір немесе бірнеше жаңа құбыры бар Unix процесі, әдетте, жаңа процестер жасау үшін `fork` функциясын шақырады. Әрбір процесс кез келген дерек өндіру немесе тұтыну алдында пайдаланбайтын құбырдың соңғы нүктесін (немесе нүктелерін) жабады. Балама ретінде, процесс жаңа жіптер жасап, олардың арасында байланыс үшін құбырды пайдалана алады. Аталған құбырлар `mkfifo` немесе `mknod` арқылы жасалуы мүмкін, содан кейін олар шақырылған кезде бағдарламаларға кіріс немесе шығыс файлы ретінде ұсынылады. Олар көп жолды құбырларды жасауға мүмкіндік береді және стандартты қателерді қайта бағыттаумен немесе `tee` командасымен біріктірілгенде ерекше тиімді.
Іске асыру
Unix-ке ұқсас көптеген жүйелерде құбыржолдың барлық процестері бір уақытта іске қосылады, олардың дерек ағындары тиісінше байланыстырылады және жүйелік жоспарлаушы (scheduler) машинадағы барлық басқа процестермен бірге басқарады. Unix құбырларын басқа құбырларды жүзеге асырулардан ерекшелендіретін маңызды ерекшелік – буферлеу ұғымы: мысалы, жіберуші бағдарлама секундына 5000 байт дерек шығара алса, ал қабылдаушы бағдарлама секундына 100 байт қана қабылдай алады, бірақ ешқандай дерек жоғалмайды. Оның орнына жіберуші бағдарламаның шығарылған деректері буферде сақталады. Қабылдаушы бағдарлама деректерді оқуға дайын болғанда, құбыржолдағы келесі бағдарлама буферден оқиды. Егер буфер толып кетсе, жіберуші бағдарлама тоқтатылады (күту күйіне қойылады), буферден қабылдағыш деректерді алып тастағанша. Linux жүйесінде буфердің көлемі 65536 байтты (64 КиБ) құрайды. Қажет болған жағдайда үлкен буферлерді ұсыну үшін bfr деп аталатын ашық кодты үшінші тарап сүзгісі қолжетімді.
Желілік құбырлар
Netcat және socat сияқты құралдар ағындарды TCP/IP сокеттеріне жалғауға мүмкіндік береді.
Тарих
Құбырлық тұжырымдамасын Дуглас Макилрой ойлап тапты және оны алғаш рет 3-ші Unix нұсқасының анықтамалық беттерінде сипаттады. Макилрой командалық қабықшалардың бір бағдарламадан екіншісіне енгізу ретінде шығыс файлын жібергенін байқады. Оның идеялары 1973 жылы іске асырылды ("бір қызу түнде", - деп жазды Макилрой) Кен Томпсон құбыр жүйелік шақыруын және құбырларды shell-ге және Unix 3-ші нұсқасындағы бірнеше құралдарға қосты. "Келесі күні, - деп жалғастырды Макилрой, - барлығы құбырларды пайдаланудың қызығына бөліскенде, біржолғы командалармен ұмытылмас той болды". Макилрой Томпсонды | белгісімен де марапаттады, бұл 4-ші нұсқадағы құбыр синтаксисін сипаттауды жеңілдетті. Unix құбырлары өздігінен дамығанмен, олардан бұрын Кен Локнер 1960 жылдары Дартмут уақыт бөлісу жүйесі үшін жасаған "коммуникациялық файлдар" болды. Тони Хоардың жүйелік байланыс процестерінде (CSP) Макилрой құбырлары одан әрі дамытылды. Apple Automator-дың белгішесіндегі робот, қайталанатын командаларды тізбектеу үшін құбыр желісі тұжырымдамасын қолданады, Unix-тің бастапқы тұжырымдамасына құрмет көрсетіп, құбыр ұстап тұр.
Басқа операциялық жүйелер
Unix жүйесінің осы мүмкіндігі MS DOS сияқты басқа операциялық жүйелерге, сондай-ақ VM/CMS және MVS-тегі CMS Pipelines жиынтығына алынып, нәтижесінде бағдарламалық инженерияның «құбырлар мен сүзгілер» дизайны үлгісі ретінде белгілі болды.