Advertisement
EBobkunov

ex1,4 sh w5

Oct 9th, 2023 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.60 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ $# -ne 1 ]; then
  4.     echo "Usage: $0 <number of subscribers>"
  5.     exit 1
  6. fi
  7.  
  8. num_subscribers=$1
  9.  
  10. # Create the directory for named pipes if it doesn't exist
  11. mkdir -p /tmp/ex1
  12.  
  13. # Create named pipes for each subscriber
  14. for ((i=1; i<=$num_subscribers; i++)); do
  15.     mkfifo /tmp/ex1/s$i
  16. done
  17.  
  18. # Compile the C programs
  19. gcc publisher.c -o publisher
  20. gcc subscriber.c -o subscriber
  21.  
  22. # Start the publisher
  23. ./publisher $num_subscribers &
  24.  
  25. # Start the subscribers in separate terminal windows
  26. for ((i=1; i<=$num_subscribers; i++)); do
  27.     gnome-terminal -- ./subscriber $i
  28. done
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement