Send signal (SIGUSR1) to process from Java app

I have a Java application that spawns a number of processes (C++ processes) running on Unix (Linux, HP-UX, AIX). I would like to send a SIGUSR1 signal to these processes from this application. What is the best way to do this?
Uncle_JAsked:
Who is Participating?
 
CEHJCommented:
You'll have to Runtime.exec kill
0
 
objectsCommented:
you can't.  what is it exactly you need to do?
 
0
 
CEHJCommented:
>>you can't.

That's incorrect
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
objectsCommented:
then please post the code to do, some of my clients would also be interested in seeing it.
0
 
CEHJCommented:
Read the following carefully:

www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

You need to do the following where the last number is the pid:

kill -s SIGUSR1 123456
0
 
objectsCommented:
Of course you can do it with native code :)  But the question is to do it from Java, which as I stated above is not possible.

The tricky bit with doing it using native code is that you need the process id which you don't have. Typicaslly that requires another exec() call to get.
A simpler solution is to do it all natively and create a script that looks up the id based on some condition you can use to identify and also do the kill. You can run that script using Runtime.exec(). Simpler than running kill using exec().

But the short answer is Java cannot send signals, you'll need native code to achieve that.

0
 
CEHJCommented:
>>The tricky bit with doing it using native code is that you need the process id which you don't have.

That's also not correct. You can do the following if you want

killall -s SIGUSR1 yourproc
0
 
objectsCommented:
thats a bit dangerous, would suggest avoiding doing that.
0
 
CEHJCommented:
Depends what the proc is
0
 
Uncle_JAuthor Commented:
My question was for the best way to send kill signals in Java. The answer is that Java must delegate this to the native OS. A simple kill command would work if the PID is known by the Java app or the proc can confidently be signaled by name. The suggestion to create a script that manages the signaling is the best idea (IMHO). Thank you all!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.