Summary of exec usage in Linux
Summarize a table first:
exec command |
action |
exec ls |
ls Span style= "font-family: the song Body;" >, No return to the original after the end |
exec <file |
exec standard input |
exec >file |
|
exec 3<file |
read into fd3 Span style= "font-family: the song Body;" > in |
sort <&3 |
fd3 |
exec 4>file |
will be written to file Span style= "font-family: the song Body;" > in |
ls >&4 |
ls fd4 |
exec 5<&4 |
create 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.
2. exec Example
1) Exec </dev/tty1//function: Use the serial terminal display character as input to exec
For example, in the key input driver: After executing exec </dev/tty1, press the key on the Development Board, the serial terminal displays the characters pressed,
Then press the OK key on the Development Board, the command will be executed, and the confirmation key will be invalid on the computer serial terminal.