You are probably looking for the timeout
command in coreutils. Since it’s a part of coreutils, it is technically a C solution, but it’s still coreutils. info timeout
for more details.
Here’s an example:
timeout 5 /path/to/slow/command with options