1

coreutils timeout and other timeout script i searched, they apply for a CDM
but i'd like to apply timeout for a linux script, if not finished for a period. like:

cd XXX && CMD && sleep 3 && kill -0 XX  

How to do it?

1 Answer 1

3

You can pass the spawning of a subshell to timeout, and have the subshell run the code that needs to be timed out:

#!/bin/bash
timeout 5 bash -c "ping google.com -c 2; ping yahoo.com -c 10"

If you clarify what you need exactly there may be cleaner ways to achieve this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.