Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Multi-process implementation of shell

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Method Summary:

1. Command & + Wait

2. pipe fifo

1.1

Example 1.1: Use command & wait to transfer all the program blocks that need to be executed by multiple processes to the background for execution.

Change the main executive program into a block with "{}", put it in the background with &, and put it in the background after four executions

A wait command is needed to wait for all background processes to finish executing.

Otherwise, the system would not wait and would continue to execute subsequent instructions until the entire program ended.

#!/ bin/bash

start=`date +"%s"`

for (( i=0; i&6 ##After each execution of the a_sub function, add an empty line so that the following process can continue

} &

done&- ##close file descriptor 6 write

exec 6&111 #Add a message to the queue, keeping the number of messages in the queue constant (number of processes)

} & #Put code blocks in the background

done

Wait for all background processes to finish

exec 111>&- #Close descriptor, write Close

exec 111

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report