Mkfifo, EXEC commands under Linux are used

Source: Internet
Author: User

Mkfifo
section:user Commands (1)
updated:1998 Year November
Index Return to Main Contents
Name (title)
Mkfifo-Create FIFO (named pipe)
Synopsis (Overview)
mkfifo [options] File ...

POSIX Options (option): [-M mode]

GNU options (Shortest form): [-M mode] [--help] [--version] [--]
DESCRIPTION (description)
Mkfifo creates a FIFO (also known as a named pipe) with the specified file name.

A "FIFO" is a special type of file that allows independent processes to communicate. A process opens a FIFO file for write operations, while another process reads it, and the data can be executed as well as the anonymous pipeline common in the shell or elsewhere.

by default, the FIFO mode that is created is 0666 (' a+rw ') minus the bits set in the umask.
options (optional)

-M mode,--mode=mode
set the mode of the FIFO that is created to mode, which can be a symbol pattern in chmod (1) and use the default mode as the starting point.


GNU Standard options (GNU std option)

--help
prints a usage message on the standard output and exits in a successful state.  
--version
Prints the version information on the standard output and exits in a successful state.  
--  
terminates the list of options.  

Summary of exec usage in Linux

EXEC Related: http://blog.csdn.net/cyberrusher/article/details/7253385

Summarize a table first:

EXEC Command

Role

exec ls

in shell ls ls after the end shell

EXEC <file< span= "" >

Use the content in file as the standard input for exec

EXEC >file

Write the contents of file as standard

EXEC 3<file< span= "" >

Read file into fd3

Sort <&3

the content read in FD3 is categorized

EXEC 4>file

writes content written to fd4 to file

LS >&4

Ls will not have a display, directly written to the fd4 , that is, the above file

EXEC 5<&4

Create a copy of the fd4 fd5

EXEC 3<&-

Close fd3

1. Exec Execution Program

Althoughexecand theSourceis executed directly in the parent process, butexecthis andSourceThere's a big difference,Sourceis to performShellscript, and will return to the previousShell. andexecexecution does not return to the previousShell, but directly to the previous landingShellas a procedure, it is copied on the line.

To illustrate:

[Email protected]:~/test#exec ls

EXP1 exp5 linux-2.6.27.54 ngis_post.sh test Xen-3.0.1-install

[Email protected]:~/test#exec >text

[Email Protected]:~/test#ls

[Email protected]:~/test#pwd

[Email Protected]:~/test#echo "Hello"

[Email Protected]:~/test#exec>/dev/tty

[Email protected]:~/test#cat text

Exp1

Exp5

linux-2.6.27.54

ngis_post.sh

Test

Text

Xen-3.0.1-install

/root/test

Hello

[Email protected]:~/test#

Exec >text is to open the standard output of the current shell to the text file

[Email Protected]:~/test#cat test

Ls

Pwd

[Email Protected]:~/test#bash

[Email protected]:~/test#exec <test< span= "" >

[Email Protected]:~/test#ls

EXP1 exp5 linux-2.6.27.54 ngis_post.sh Test text Xen-3.0.1-install

[Email protected]:~/test#pwd

/root/test

[Email protected]:~/test#

[Email protected]:~/test#exit # Automatic execution

2. exec redirection

Let's go first. Look in the/dev/fd/directory:

[Email protected]:~/test#cd/dev/fd

[Email Protected]:/dev/fd#ls

0 1 2 255

There are four items by default:0 is the standard input and the default is the keyboard.

1 is the standard output, the default is the screen /dev/tty

2 is a standard error, the default is also the screen

255

When we execute exec 3>test :

[Email protected]:/dev/fd#exec 3>/root/test/test

[Email Protected]:/dev/fd#ls

0 1 2) 255 3

[Email protected]:/dev/fd#

See, more than a 3, that is, added a device, here can also experience the Linux device is the concept of the file. at this time fd3 is the equivalent of a pipeline, and redirects to the fd3 file will be written in test . This redirection can be turned off with exec 3>&-.

[Email protected]:/dev/fd#who >&3

[Email Protected]:/dev/fd#ls >&3

[Email protected]:/dev/fd#exec 3>&-

[Email Protected]:/dev/fd#cat/root/test/te

Test text

[Email Protected]:/dev/fd#cat/root/test/test

Root Tty1 2010-11-16 01:13

Root pts/0 2010-11-15 22:01 (192.168.0.1)

Root PTS/2 2010-11-16 01:02 (192.168.0.1)

0

1

2

255

3

3. Application Examples:

EXEC 3<test< span= "" >

While Read-u 3 pkg

Do

echo "$pkg"

Done

Mkfifo, EXEC commands under Linux are used

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.