I have a Java app that creates an external process and reads the process' stdout through an InputStream. I need to be able to kill the process when I am done with it. Is there a way to send a SIGINT signal to this process? (as if I pressed Ctrl+C from the console).  The external process is not my code and I cannot modify it.
23537
How do I stop a Java process gracefully in Linux and Windows?  When does Runtime.getRuntime().addShutdownHook get called, and when does it not?  What about finalizers, do they help here?  Can I send some sort of signal to a Java process from a shell?  I am looking for preferably portable solutions.
59094
How do I get the id of my Java process?   I know there are several platform-dependent hacks, but I would prefer a more generic solution.
118279
I'm creating child processes with fork() in C/C++. When the parent process ends (or is killed for some reason) I want all child processes to be killed as well. Is that done automatically by the system? Or I have to do it myself?  Thanks.    Pre-existing similar questions:
512
I'm using the  to start a subprocess and connect to its output stream (standard output). I want to be able to execute non-blocking reads on its standard output. Is there a way to make .readline non-blocking or to check if there is data on the stream before I invoke .readline? I'd like this to be portable or at least work under Windows and Linux. Here is how I do it for now (it's blocking on the .readline if no data is available): p = subprocess.Popen('myprogram.exe', stdout = subprocess.PIPE) output_str = p.stdout.readline()
122811
Occasionally I need to specify a "path-equivalent" of one of the standard IO streams (stdin, stdout, stderr).  Since 99% of the time I work with Linux, I just prepend /dev/ to get /dev/stdin, etc., and this "seems to do the right thing".  But, for one thing, I've always been uneasy about such a rationale (because, of course, "it seems to work" until it doesn't).  Furthermore, I have no good sense for how portable this maneuver is.  So I have a few questions:   In the context of Linux, is it safe (yes/no) to equate stdin, stdout, and stderr with /dev/stdin, /dev/stdout, and /dev/stderr? More generally, is this equivalence "adequately portable"?   I could not find any POSIX references.
56598
I have a Java program that I'd like to daemonize on a linux system. In other words, I want to start running it in a shell and have it continue running after I've logged out. I also want to be able to stop the program cleanly.  I found  which uses a combination of shell scripting and Java code to do the trick. It looks good, but I'd like something simpler, if possible.  What's your preferred method to daemonize a Java program on a Linux system?
55913
So I've got a persistent program running in the background. Killing it just causes it to restart with a different PID. I'd like to suspend it (put it to sleep without actually killing it). Does kill -9 do this? If not, how should this be done?
123988
I have a program which produces useful information on stdout but also reads from stdin. I want to redirect its standard output to a file without providing anything on standard input. So far, so good: I can do:  program &gt; output   and don't do anything in the tty.  However, the problem is I want to do this in the background. If I do:  program &gt; output &amp;   the program will get suspended ("suspended (tty input)").  If I do:  program &lt; /dev/null &gt; output &amp;   the program terminates immediately because it reaches EOF.  It seems that what I need is to pipe into program something which does not do anything for an indefinite amount of time and does not read stdin. The following approaches work:  while true; do sleep 100; done | program &gt; output &amp; mkfifo fifo &amp;&amp; cat fifo | program &gt; output &amp; tail -f /dev/null | program &gt; output &amp;   However, this is all very ugly. There has to be an elegant way, using standard Unix utilities, to "do nothing, indefinitely" (to paraphrase man true). How could I achieve this? (My main criteria for elegance here: no temporary files; no busy-waiting or periodic wakeups; no exotic utilities; as short as possible.)
114946
I'm writing a bash script to use inotifywait to monitor a directory and kick off actions when changes are detected. Something like:  inotifywait -m ... | while read f; do something; done   Since inotifywait doesn't terminate by itself, this script will not halt.  So my plan was to get the PID of the inotifywait process, save it to a file and have a different process kill it later, say like:  inotifywait -m ... | { echo ??PID?? &gt; pid-file; while ... }   But I don't know how to get the PID.  Is there a simple way to achieve this?  Another way is just to save the PID of the shell-script $$ to the file and kill the entire shell-script but I wanted to do some cleanup after the while loop.  I have tried using coproc and I think it will work but it seems like more complication than necessary.
82849
I'm trying to capture all of the output of a build operation, and send it to myprogram. I seem to only be able to capture part of it. This is what I'm trying:  make clean &amp;&amp; make DISABLE_ID3TAG=1 CFLAGS="-O2 -DNDEBUG -W64" | myprogram &amp;2 &gt; 1   I also tried:  make clean &amp;&amp; make DISABLE_ID3TAG=1 CFLAGS="-O2 -DNDEBUG -W64" &amp;2 &gt; 1 | myprogram   Basically I want to send everything to stdout and then do something with that. Currently I'm only capturing part of the output, and the other part is going to the screen. How can I pipe everything to another program?
92456
Alright, I have been doing the following (variable names have been changed):   FileInputStream fis = null; try {     fis = new FileInputStream(file);      ... process ...  } catch (IOException e) {     ... handle error ... } finally {     if (fis != null)         fis.close(); }    Recently, I started using FindBugs, which suggests that I am not properly closing streams.  I decide to see if there's anything that can be done with a finally{} block, and then I see, oh yeah, close() can throw IOException.  What are people supposed to do here?  The Java libraries throw too many checked exceptions.
104676
I have a Java application that I run from a console which in turn executes an another Java process. I want to get a thread/heap dump of that child process.  On Unix, I could do a kill -3 &lt;pid&gt; but on Windows AFAIK the only way to get a thread dump is Ctrl-Break in the console. But that only gives me the dump of the parent process, not the child.  Is there another way to get that heap dump?
27306
When ever I need to kill a background process I do ps -e | grep &lt;process_name&gt;  Which prints something like this 1766 ? 00:00:13 conky , Then I use the process ID to kill it like so kill 1766 .   Is there any way I can simplify this ? Make it quicker ? reduce the amount of typing ?
119201
Can a Java application be loaded in a separate process using its name, as opposed to its location, in a platform independent manner?  I know you can execute a program via ...  Process process = Runtime.getRuntime().exec( COMMAND );   ... the main issue of this method is that such calls are then platform specific.   Ideally, I'd wrap a method into something as simple as...  EXECUTE.application( CLASS_TO_BE_EXECUTED );   ... and pass in the fully qualified name of an application class as CLASS_TO_BE_EXECUTED.
96499
I have two programs, one of them prints something first, they need to communicate with each other with their standard IO.  Is there a way in Bash to pipe stdout of two programs to each other? I know I could do this in C with forks and dups, but is there a way with pure Bash?
101553
I sometimes get a little confused by all of the signals that a process can receive. As I understand it, a process has a default handler (signal disposition) for each of these signals, but it can provide its own handler by calling .  So here is my question: what causes each of the signals to be sent? I realize that you can manually send signals to running processes via the -s parameter to kill, but what are the natural circumstances under which these signals are sent? For example, when does SIGINT get sent?  Also, are there any restrictions on which signals can be handled? Can even SIGSEGV signals be processed and control returned to the application?
9812
How should I run another program from within my C program? I need to be able to write data into STDIN of the launched program (and maybe read from it's STDOUT)  I am not sure if this is a standard C function. I need the solution that should work under Linux.