[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Send signal (SIGUSR1) to process from Java app

Posted on 2009-04-24
10
Medium Priority
?
3,823 Views
Last Modified: 2013-12-20
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?
0
Comment
Question by:Uncle_J
  • 5
  • 4
10 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 1000 total points
ID: 24227909
You'll have to Runtime.exec kill
0
 
LVL 92

Expert Comment

by:objects
ID: 24229536
you can't.  what is it exactly you need to do?
 
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24229612
>>you can't.

That's incorrect
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 24229631
then please post the code to do, some of my clients would also be interested in seeing it.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24229667
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
 
LVL 92

Assisted Solution

by:objects
objects earned 1000 total points
ID: 24229702
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 24229727
>>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
 
LVL 92

Expert Comment

by:objects
ID: 24229741
thats a bit dangerous, would suggest avoiding doing that.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24229795
Depends what the proc is
0
 

Author Closing Comment

by:Uncle_J
ID: 31574346
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Six Sigma Control Plans
Suggested Courses
Course of the Month19 days, 13 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question