Exit code 1 means the command is not fully executed,it must return 0, my guess is that the system has stopped responding before finishing the command,make sure that the process are synchronized and that the process B for instance waits for process A to finish inorder to start Operating.
However with my experience in using Ghostscript, i think version 9.06 is more stable than the recent ones of it, also adding the parameter -dUseTrimBox wont harm.
this what i suggest hope it helps .