Forum Bugs

Prince orphan processes on linux. How to kill them?

andreizet
So I've found a problem related to Prince orphan processes, on linux.

We are running Prince from Java and somehow, if JVM dies, Prince process is not killed so it will remain hanged, eating memory and CPU, but doing nothing.

I've found a way to reproduce this:

1. I've created a function that converts a html page to pdf using Prince java wrapper.
2. Runned that from a linux terminal.
3. When Prince starts, I simply killed the java process using "kill -9 pid".

Now if you look into processes using ps -aux, you will see a Prince process with values bigger than 0 for CPU & MEMORY.

Please note that this steps are never used in production, it is just some replication of the original case.
But for example, if JVM dies unexpedtedly because of a OutOfMemoryError or something that really kills that java process while Prince is doing something, it will become an orphan.


Also, when I killed the java process, Prince simply stops writing in current log file, which makes me think that from now on, it is in some kind of sleep.

A solution is to set a cron job that from time to time, will get all Prince orphan processes using something similar to this ps -elf | head -2; ps -elf | awk '{if ($5 == 1 && $15~'/prince/') {print $0}}', and kill them. But I really don't like this solution, maybe there is something cleaner.

Anyone had similar issues? Is there a way to automatically kill that orphan process?

Thanks!
mikeday
We will investigate this, Prince is supposed to terminate automatically when the Java process closes the pipe. Which convert method are you calling in the Java wrapper?
andreizet
I'm using convertMultiple.

I've done another test, and if instead of kill -9 pid, if I use ctrl + c in the terminal where I launch my main class, Prince process is killed.

But I think this is happening because using ctrl + c shuts down JVM.