>_ IzzyLab

Hands-on task

This task is step 11 of the course “Processes and signals”

timeout: limit the time

easy~4 min

/opt/jobs/ has two jobs, fast.sh and slow.sh; neither may run longer than 3 seconds. Run each one via timeout with a 3-second limit and write the return codes to /root/rc.txt: on the first line — the code of the fast.sh run, on the second — slow.sh.

What you'll practise:
  • timeout
  • time limit
  • return code
  • $?

Topic breakdown

timeout DURATION COMMAND runs a command and forcibly terminates it if it doesn't finish within the allotted time — a safeguard for scripts against hangs. The return-code semantics matter: if the command finished on its own, its own code is returned, but if the timeout fired — a special code 124. The exit code of the last command is always in $?, and you must read it as the very next instruction, before another command overwrites it.

What's checked

  1. the first line has the code of fast.sh
  2. the second line has the code of slow.sh stopped by the timeout

What it looks like