# How can I run 2 commands simultanionsly?



## for.ggame.playing (Jul 25, 2020)

Hi there, I wander is it theoretically possible that I can execute 2 commands at the same time using scripts? 
Say I want to ping 2 hosts at the same time, how do I do it?


----------



## Phishfry (Jul 25, 2020)

Use an ampersand in between programs.








						10 Useful Chaining Operators in Linux with Practical Examples
					

This Article aims at throwing light on frequently used command-chaining operators, with short description and corresponding examples which surely will increase your productivity.




					www.tecmint.com
				




Also you could open a second virtual terminal with ctl-alt-F2 and run commands on it at the same time.


----------



## fender0107401 (Jul 26, 2020)

for.ggame.playing said:


> Hi there, I wander is it theoretically possible that I can execute 2 commands at the same time using scripts?
> Say I want to ping 2 hosts at the same time, how do I do it?



Google multi-thread.


----------



## Jose (Jul 26, 2020)

FreshPorts -- net/fping: Quickly ping multiple hosts without flooding the network
					

A tool to quickly ping N number of hosts to determine their reachability without flooding the network.       fping is different from ping in that you can specify any number of 	 hosts on the command line, or specify a file containing the lists 	 of hosts to ping. Instead of trying one host until...




					www.freshports.org


----------



## kpedersen (Jul 26, 2020)

In shell you run them with *&* (to background).
You then immediately store their PID (process ID) via the *$!* variable.
And then you can use *wait* to halt execution until that process is complete.

For more info, check out: https://linuxhint.com/wait_command_linux/

I used to be worried about juggling PIDs like this because the kernel *can* reuse PIDs and I might get unlucky. However I then realised that wait can only wait on child processes, avoiding the problem altogether.

For more info check out:








						Bash: Is it possible to stop a PID from being reused?
					

Is it possible to stop a PID from being reused?  For example if I run a job myjob in the background with myjob &, and get the PID using PID=$!, is it possible to prevent the linux system from re-




					stackoverflow.com


----------

