Advertisement
EBobkunov

ex1.sh w5

Oct 8th, 2023
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.50 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ $# -ne 1 ]; then
  4.     echo "Usage: $0 <num_subscribers>"
  5.     exit 1
  6. fi
  7.  
  8. num_subscribers=$1
  9.  
  10. # Compile the C programs
  11. gcc publisher.c -o publisher
  12. gcc subscriber.c -o subscriber
  13.  
  14. # Run the publisher in the background
  15. ./publisher $num_subscribers &
  16.  
  17. # Run the subscribers in separate terminal windows
  18. for ((i = 1; i <= num_subscribers; i++)); do
  19.     x-terminal-emulator -e ./subscriber $i &
  20. done
  21.  
  22. # Wait for all subscribers to finish
  23. wait
  24.  
  25. # Clean up
  26. rm publisher subscriber
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement