Code:
#!/bin/bash
# ==============================================================
# CPU limit daemon - set PID's max. percentage CPU consumptions
# ==============================================================

# Variables
CPU_LIMIT=20        # Maximum percentage CPU consumption by each PID
DAEMON_INTERVAL=3   # Daemon check interval

while sleep $DAEMON_INTERVAL
do
   NEW_PIDS=$(top -b -n1 | gawk 'NR>6 && $9>CPU_LIMIT {print $1}' CPU_LIMIT=$CPU_LIMIT)         # Violating PIDs
   LIMITED_PIDS=$(ps -eo args | gawk '$1=="cpulimit" {print $3}')                               # Already limited PIDs
   QUEUE_PIDS=$(diff <(echo "$NEW_PIDS") <(echo "$LIMITED_PIDS") | grep '^<' | sed 's/< //g')   # PIDs in queue

   for i in $QUEUE_PIDS
   do
      cpulimit -p $i -l $CPU_LIMIT -z &   # Limit new violating processes
   done
done

ERROR:

sh cpulimit.sh
cpulimit_daemon.sh: command substitution: line 31: syntax error near unexpected token `('
cpulimit_daemon.sh: command substitution: line 31: `diff <(echo "$NEW_PIDS") <(echo "$LIMITED_PIDS") | grep '^<' | sed 's/< //g')'


On Ubuntu linux it worked.

But I used with "comm" command the script still error.

Code:
QUEUE_PIDS=$(comm -23 <(echo "$NEW_PIDS" | sort -u) <(echo "$LIMITED_PIDS" | sort -u) | grep -v "^$")   # PIDs in queue