Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/bash
- PID_MAIN=$$
- # notify subshells on ctrl-c
- trap "kill 0" SIGINT
- function wrk() { while read data; do echo $1 _${data}_; done }
- function shw() {
- pid=$1
- fd=$2
- while IFS= read result; do
- echo out: $result
- done < /proc/${pid}/fd/${fd}
- }
- # return worker names like "wrk0"
- function workers() {
- for i in {1..5}; do
- echo wrk${i}
- done
- }
- # spawn worker and printer processes
- for worker in $(workers); do
- eval "coproc ${worker} { wrk $worker; }"
- fdname="${worker}[0]"
- ( shw ${PID_MAIN} ${!fdname} ) &
- done
- echo Filedescriptors of main process:
- ls -lFh /proc/$$/fd/
- echo List of processes in processgroup:
- jobs -l
- echo feeding some test data to the workers
- for worker in $(workers); do
- fdname="${worker}[1]"
- echo $fdname
- echo test > /proc/$PID_MAIN/fd/${!fdname}
- done
- sleep 100
- kill 0
- exit
Add Comment
Please, Sign In to add comment