[英]How to make a program that executes another C program multiple times at the same time?
I made a simple client-server program in c using sockets and now i want to test it ,by simulating many clients connecting to the server at the same time!I wrote a script to execute the client: ./client
20 times but it didn't work for me since it waited for each client to finish. 我使用套接字在C语言中编写了一个简单的客户端-服务器程序,现在我想通过模拟同时连接到服务器的许多客户端来对其进行测试!我编写了一个脚本来执行客户端: ./client
20次,但没有因为它等待每个客户端完成,所以对我不起作用。
Also i wrote another program in c ,this time with threads so it could execute each client with system(./client)
and then detach the thread ,but again i had the same problem! 我也用c编写了另一个程序,这次是用线程编写的,因此它可以用system(./client)
执行每个客户system(./client)
,然后分离线程,但是我又遇到了同样的问题!
So what is the correct way to implement this? 那么实现此目标的正确方法是什么?
最简单的解决方案是执行您的shell脚本,但是在./clientk调用之后加上&,这将把它放在后台并立即运行下一个命令
Here's a really simple way to launch a number of clients without waiting for each to complete: 这是启动多个客户端而无需等待每个客户端完成的非常简单的方法:
#!/bin/bash
for i in $(seq 0 20)
do
./client &
done
wait
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.