I want to do stress testing of my software. I have multiple testcases with me with different runtime.

Currently, I'm running stress utility with required options and run testcase in another terminal. Once that testcase gets over, I kill stress process with ctr+C.

Now, I want to create a script which will run the stress utility and then run testcase and should be able to kill stress process after my testcase gets over.

I have a workaround as of now with stress i.e. --timeout option. So I'm running as follows:

stress -c 16 --timeout 3600 
./runme //Testcase script

After an hour, stress utility gets finished. But there is following issue with the above mentioned workaround i.e. ./runme can take 1 min to 2-3 hours of time. So I can't put timeout value beforehand.

Please suggest a way to deal with this.


Run your stresser in the background and note it's pid which will be used to kill it later on. And now start your testcases in the foreground. After the testsuites finish, you go ahead n kill the stresser now:

stress -c 16 & #<--- note no timeoutoption given and assuming now it runs forever

./rune //Testcases script

kill -9 "$pid_stress"
  • It doesn't work in practice. Actually command stress -c 16 invokes 16 processes. They are invoked by the parent stress process whose pid we get as you have mentioned. When I kill that pid, then others do not get killed and their ownership goes to its parent process. – Vivek Agrawal Mar 31 '17 at 13:51
  • 1
    Then in that case you need to gather the pids of those 16 childs as well. You didnt state that in your query initially. pstree "$pid" -p -a -l > x; kill -9 $(cut -d, -f2 x | cut -d' ' -f1) – user218374 Apr 1 '17 at 16:34
  • Of course, I didn't state that because I was assuming that you knew how stress work. Thanks a lot for your answer. It really solves my original problem. I made some minor changes in your command to avoid any file operation: pstree $pid_stress -p -a -l | cut -d, -f2 | cut -d' ' -f1 | xargs kill -9 – Vivek Agrawal Apr 3 '17 at 13:35
  • Meanwhile, I was trying the following in python: os.setpgrp() # create group before stress invocation ./runme os.killpg(0, signal.SIGKILL) # kill all processes in my group This has worked for me. But I will prefer your way. – Vivek Agrawal Apr 3 '17 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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