How to run a program on Linux multiple times in parallel for testing
Daniel Nashed – 5 March 2026 20:57:26
This is really cool. I did't know about those options for xargs. And I never used seq.
It can be used for a lot of things.
Here is an example to create test mails
seq 1 50 | xargs -P50 -I{} nshmailx -to test@example.com -subject "TestMail {}" -server 127.0.0.1 -port 25
Here is a more simple example which demonstrates what it does.
seq 1 10 | xargs -P50 -I{} echo '"Test{}"'
seq counts from 1 to 10 and prints the result to stdout.
It could be also used to start at a different value and you can add an optional increment.
There are two interesting options for xargs.
-P50
run the specified program with 50 instances in parallel
-I{}
specify a place holder which will be replaced by the text from stdin -- in this case the number.
What is also cool is that it works in single and double quotes.
seq 1 10 | xargs -P50 -I{} echo '"Test{}"'
"Test1"
"Test2"
"Test3"
"Test4"
"Test5"
"Test6"
"Test7"
"Test8"
"Test9"
"Test10"
- Comments [0]