[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: regulating the time a process can run with crontab?



Brent -

One way to limit the duration of a command is to run it in a
subprocess (i.e. put the shell command in parentheses) and have the
parent kill it.  Here's an example:

  #!/bin/bash
  # try to send a string to the synthesizer via four different serial
  #ports
  for x in 0 1 2 3; do
      (DTK_PORT=/dev/ttyS$x
      echo "trying $DTK_PORT"
      stty sane 9600 raw -echo crtscts <$DTK_PORT &&\
      stty -echo                       <$DTK_PORT &&\
      stty ixon ixoff                  <$DTK_PORT &&\
      echo "this is /dev/t t y s $x" $'\r' >$DTK_PORT )&
  # if one of the above commands hangs, kill the process
      sleep 2; kill $! >/dev/null 2>&1
  done

	              - Jim Van Zandt
  





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]