-1

I have a VPS server where I am updating the code and one step is to execute UglifyJS, this is very slow and takes about 20 seconds. Our VPS will always kill the process that takes 100% CPU for longer than 10 seconds. So what I do is start uglify script, count to 7, press Control+Z so the process pauses, count to 10, type fg and press ENTER, then count to 7, and repeat this until Uglify is finished.

Is there a way to automate this 'pausing' or other way to prevent VPS from killing Uglify?

exebook
  • 32,014
  • 33
  • 141
  • 226

1 Answers1

1

if you've got Python installed on the target machine, you could do something like:

import sys
import os
import subprocess
import signal
import time

with subprocess.Popen(sys.argv[1:]) as proc:
    while True:
        try:
            proc.wait(7)
        except subprocess.TimeoutExpired:
            os.kill(proc.pid, signal.SIGSTOP)
            time.sleep(10)
            os.kill(proc.pid, signal.SIGCONT)
        else:
            break

sys.exit(proc.returncode)

this uses your timing, but something faster might be better for code

I saved this as run_slowly.py, and can run as:

$ python3 run_slowly.py program arg1 arg2

from the shell

Sam Mason
  • 15,216
  • 1
  • 41
  • 60