Parallel processing in Bash script

27 خرداد 1402 - خواندن 2 دقیقه - 353 بازدید


Parallel processing in Bash script

How to do parallel processing in bash script

For parallel processing in Bash Script, one solution is to use the execution of commands in the background. You can use the ampersand at the end of each function to execute it in the background and have the terminal available to execute other commands.

Use kill command to kill processes.


#!/bin/bash

touch Parallel_processing_1

touch Parallel_processing_2

touch Parallel_processing_3

ping 8.8.8.8 > Parallel_processing_1_8.8.8.8 &

ping 4.2.2.4 > Parallel_processing_2_4.2.2.4 &

ping 1.1.1.1 > Parallel_processing_3_1.1.1.1 &


64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=79.5ms

Mostafa jahanpur