timeout is not a builtin/function of the
bash shell or of any shell for that matters (except if you want to consider busybox sh, where busybox commands can be seen as builtin of the shell).
timeout is a non-standard standalone utility of which there exists several often incompatible implementations (there also exist
timelimit utilities with the same function).
timeout 10 sudo slowcommand
Current versions of the GNU implementation of the
timeout utility (from GNU coreutils, again distinct from the GNU shell,
sudo slowcommand and sends the SIGTERM command to its own process group if
sudo has not finished within 10 seconds.
However the process running
sudo has changed user id, and the process that
sudo has spawned to run
slowcommand will also run with a different uid, so even though both processes will be in the same process group as that running
timeout will not have the right to send signals to them.
There are possible ways around that. You can arrange for the kernel to send some signals instead of some unprivileged process like that running
timeout. For instance, you could have it send:
slowcommand writes to a closed pipe:
sudo slowcommand | timeout 10 cat
would cause SIGPIPE to be sent to
slowcommand if it writes something to stdout after 10 seconds.
slowcommand will all run in the same process group, so that's the same as
timeout 10 sudo slowcommand | cat).
slowcommand uses more than its assigned limit of CPU time:
(ulimit -t 10; exec sudo slowcommand)
slowcommand to be killed if it uses 10 seconds of CPU time.
SIGHUP if the terminal hangs up, and
sudo is not session leader:
timeout 10 script -qfc 'sudo slowcommand; exit' /dev/null
SIGINT/SIGQUIT. You could also use things like
screen to simulate a terminal and send a
^C character after 10 seconds for SIGINT to be sent to the foreground process group of that terminal.