Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am making bash script for my use. How can i run a command for certain time, like 20 second and terminate command? I tried a lot of solutions but nothing works, I also tried timeout command with no success. Please give me some solution for this.

for example: I want to run this command in script and terminal after 10 sec

some command
share|improve this question

Hm, that should do the trick:

xmessage "Hello World" &
sleep 10; kill $pidsave

xmessage provides a quick test case here (in your case the airodump command should go there); & puts it into background.

$! holds the PID of the last started process (see e.g.; the PID gets saved into the variable pidsave.

After some waiting (sleep), send a TERM signal to the process.

share|improve this answer
Thanks buddy it works but Now I have 1 problem. I want to see output which is created by command but xmessage windows doesn't show anything. – Umair Riaz May 8 '13 at 17:51
problem solved. Thanks guys – Umair Riaz May 8 '13 at 18:13
@UmairRiaz: xmessage was just an example. To adapt your example in the question and log the output of the command use some command > logfile & in the first line. Afterwards you can analyse logfile. – mpy May 8 '13 at 21:00

From the bash prompt you can use"

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.