You need to rescue
specifically for Timeout:Error
since Timeout::Error is not a standard error:
pid = Process.spawn("my_process_command")
begin
Timeout.timeout(16) do
`my_timeout_command`
Process.wait(pid)
end
rescue Timeout::Error
system("clear")
puts 'Process not finished in time, killing it'
Process.kill('TERM', pid)
end