1

I has this error when I run bash script that run another bash scripts and recursively run itself.

In scripts I use xdotool, create counters and in each script I use $RANDOM call (even is a file that call $RANDOM in while-loop : max 20 iteration) And each command is saved with echo 'command' redirecting stream into file.

It give me this error:

./somescript.sh: fork: Cannot allocate memory

About OS: Antergos 64bit + Openbox + 8Gb RAM

Was opened: qtcreator, lxterminal, my qt app (100Mb) Now size of log file is 3,5 МіB. My ulimit -a:

[user@workstation MonkeyClicker]$ ulimit -a
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 31856
max locked memory       (kbytes, -l) 1024
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 31856
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

My run.sh script:

#!/bin/bash

if [ -z $1 ]
then
        echo ' '
        echo '***************MONKEY TESTING TOOL HELP***************'
        echo ' '
        echo 'command: run.sh [start delay]'
        echo '[start delay] - means that you have X seconds to start your program'
        echo 'for example : run.sh 3s 0.1s'
        echo ' '
else
        mkdir -p logScript
        ./monkeyTestingTool.sh $1 > $PWD/logScript/script.sh
fi

My monkeyTestingTool.sh script:

!/bin/bash

if [ $1 ]
then
        echo '#Started in:' $date
        echo '#MONKEY TESTING START, BE CAREFUL!'
        echo '#You have' $1 'seconds to open your app for testing ...'
        sleep $1
fi

echo $(xdotool getmouselocation --shell)
echo 'xdotool mousemove --sync $X $Y'

RANGE=7
CHOOSE=$RANDOM
let "CHOOSE %= $RANGE"

case $CHOOSE in
0) sh ./move.sh
;;
1) sh ./callContextMenu.sh
;;
2) sh ./typeRandom.sh
;;
3) xdotool click 1 #this is leftMouseClick
;;
4) sh ./keyPressing.sh
;;
5) sh ./move.sh
;;
6) sh ./dragDrop.sh
#*) TODO: drag and drop
esac

./monkeyTestingTool.sh

And for example my callContextMenu.sh script:

#!/bin/bash

echo $(xdotool getmouselocation --shell)
echo 'xdotool mousemove --sync $X $Y'

echo 'xdotool click 3'
xdotool click 3

LASTKEY=0
RANGESTEPS=20
STEPS=$RANDOM
let "STEPS %= $RANGESTEPS"

while [ $STEPS != 0 ]; do
        RANGE=5
        CHOOSE=$RANDOM
        let "CHOOSE %= $RANGE"
        let STEPS=STEPS-1
        LASTKEY=$CHOOSE
        case $CHOOSE in
        0) xdotool key Up
        echo 'xdotool key Up'
        ;;
        1) xdotool key Left
        echo 'xdotool key Left'
        ;;
        2) xdotool key Down
        echo 'xdotool key Down'
        ;;
        3) if [ $STEPS == 1 ]
        then
                echo 'xdotool key Return'
                xdotool key Return
        fi
        ;;
        4) xdotool key Right
        echo 'xdotool key Right'
        ;;
        esac
done

if [ $LASTKEY != 3 ]
then
        echo 'xdotool key Return'
        xdotool key Return
else
        echo 'xdotool key Down'
        echo 'xdotool Return'
        xdotool key Down
        xdotool key Return
fi
3
  • 1
    Please edit your question and i) show us the actual scripts you're running (even better, show us a minimal example that reproduces the error) and ii) explain exactly how you're launching the scripts and iv) show us the precise error message. In the question, not the title.
    – terdon
    Aug 22, 2016 at 15:56
  • 1
    "unlimited" doesn't mean you can't run out of memory with recursion.
    – Jeff Schaller
    Aug 22, 2016 at 15:59
  • Fixed. I have idea to kill monkeyTestingTool.sh every 5 minutes. Aug 22, 2016 at 16:07

1 Answer 1

4

Your last line of monkeyTestingTool.sh calls itself

./monkeyTestingTool.sh

This means you'll soon end up with hundreds and hundreds of copies of this program running.

If you want to re-run the script then make that last line

exec ./monkeyTestingTool.sh

Or else put the whole thing in a while loop similar to:

while [ 1 ]
do
  CHOOSE=$RANDOM
  let "CHOOSE %= $RANGE"

  case $CHOOSE in
  0) sh ./move.sh
  ;;
  ....
  esac
done
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .