2

Hi our server has a weird issue where once a month or so a GS (GhostScript) process gets stuck and eats 10-75% CPU until I kill the process. strace hasn't provided anything useful so until I can resolve this correctly I'd like to create a script that checks every few minutes and kills any GS process that has been running for longer than 5 minutes. Under normal circumstances this process should complete in a few seconds to a minute at most.

In top the command shows up as "GS". How do I go about doing this? I'm assuming I need to write a BASH script as well as set it to run on an interval? The box is a webserver running CentOS 6.5.

Thanks!

Jonathan
  • 207
  • 5
  • 10
  • What spawns the ghostscript process? I'd really take the approach of fixing the root issue... can you give more information about the application? – ewwhite Oct 12 '14 at 21:43
  • We use PrinceXML to generate PDF's through their PHP wrapper. I pass an HTML file, Prince converts it to a PDF using GhostScript for font rendering. I don't call GS myself it's done through their API. From the logs I can tell which account/file caused GS to hang, but once I kill the process I can re-run the export and it works every time. The only clue that may be causing it, and I'm not sure if this is actually the case, is if a user clicks repeatedly I cancel the AJAX call that requests a PDF and resend. Perhaps cancelling the request it causing it to occasionally hang? – Jonathan Oct 13 '14 at 11:47
  • I've tested cancelling AJAX calls and I haven't been able to replicate the hang. – Jonathan Oct 13 '14 at 11:54

1 Answers1

2

Use killall command as follow, Replace Process_Name with the GS process name,

killall  --older-than 5m Process_Name

To create a script file

touch myscript.sh

chmod +x myscript.sh

echo "killall  --older-than 5m Process_Name" > myscript.sh

To run the script every 5 mins, Assuming myscript is located in the root directory.

echo "*/5 * * * * /root/myscript.sh" >> /etc/crontab
MohyedeenN
  • 1,063
  • 1
  • 12
  • 15