Entrada de FAQ BASH # 68: "Como faço para executar um comando e abortar (timeout) após N segundos?" / a>
FIRST check whether the command you're running can be told to timeout directly. The methods described here are "hacky" workarounds to force a command to terminate after a certain time has elapsed. Configuring your command properly is always preferable to the alternatives below.
If the command has no native support for stopping after a specified time, then the best alternatives are some external commands called timeout and doalarm. Some Linux distributions offer the tct version of
timeout
as a package. There is also a GNU version of timeout, included in recent coreutils releases.