表面上看来这么做和单独使用重定向效果一样,但是当程序需要多个输入时候,单独的重定向只能让read读取单独一个文件内容无法为每个单独指定输入。
4、通过文件句柄创建多进程
read -u 读取文件描述符的方式读取字符串
设置文件描述符中回车数量为预设进程数目
通过循环建立多进程
#!/bin/bash
#filename: mproc.sh
# Revision: 1.1
# Date: 2017-06-09
# Author: linuxidc
# Email: memeda@163.com
# QQ: 787743742
# Website:
# Description: This is use for test shell multiprocess
# Notes:
# -------------------------------------------------------------------------------
# Copyright: 2017 (c) linuxidc
# License: GPL
#
# This program is free software; you can Redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# you should have received a copy of the GNU General Public License
#
# If any changes are made to this script, please mail me a copy of the changes
# -------------------------------------------------------------------------------
#Version 1.0
#
main_sub() {
local loop_time=$(( $1 % 7 ))
echo -e "$i\t----\t---$loop_time begin"
sleep $loop_time
echo -e "$i\t-----\t$loop_time end"
}
tmp_file="/tmp/.fifo-$$"
mkfifo $tmp_file #创建fifo文件用于进程通信
exec 6<>$tmp_file #创建文件句柄6为管道
rm -f $tmp_file
my_thread=6 #限制进程数
runtime=50
for (( i=0 ; i < $my_thread ; i++ )) ; do
echo