|
From: Mirko V. <mir...@gm...> - 2024-02-03 15:40:13
|
Hello, I am writing an interface to gnuplot from common lisp (CL). The CL process calls gnuplot and sets up the input & output handles. I am able to start the gnuplot process, send commands, and fetch output (such as from "show version"). I can also generate plots. I can shut down the process by sending the "exit" command. But I'd also like to send a signal (such as SIGTERM) to shut gnuplot down. I tried this by sending the numeral 15 but that did not shut down the process. I searched the source code at a fork on github, found SIGTERM there, but not what value to use for it. Nor am I sure that SIGTERM would shut it down. Please note, that I am very new to this kind of communication with processes. I am possibly/likely misunderstanding how things are supposed to work. Maybe I am misunderstanding the purpose of SIGTERM, or don't have the correct code for it. Thanks, Mirko |
|
From: Peter R. <p.r...@sh...> - 2024-02-04 15:19:52
|
Two questions: 1) Why do you want to send a SIGTERM to the process? Why isn't "exit" (which you say works) good enough? The signal handler -- either the default or an over-ridden version -- would typically invoke the system call that actually shuts down the process. Which is probably what the gnuplot "exit" command does one way or another. 2) What OS are you using? Windows, for example, doesn't use signals - they are a UNIX/Linux/MacOS(?) thing. I suspect sending a signal on Windows will just be ignored, which is consistent with the behaviour you seem to be observing. FWIW: The exact value of SIGTERM will be defined in a C header file somewhere, probably "signals.h". P. On 03/02/2024 15:39, Mirko Vukovic wrote: > Hello, > > I am writing an interface to gnuplot from common lisp (CL). The CL process > calls gnuplot and sets up the input & output handles. > > I am able to start the gnuplot process, send commands, and fetch output > (such as from "show version"). I can also generate plots. > > I can shut down the process by sending the "exit" command. > > But I'd also like to send a signal (such as SIGTERM) to shut gnuplot down. > > I tried this by sending the numeral 15 but that did not shut down the > process. > > I searched the source code at a fork on github, found SIGTERM there, but > not what value to use for it. Nor am I sure that SIGTERM would shut it down. > > Please note, that I am very new to this kind of communication with > processes. I am possibly/likely misunderstanding how things are supposed to > work. Maybe I am misunderstanding the purpose of SIGTERM, or don't have the > correct code for it. > > Thanks, > > Mirko > > _______________________________________________ > gnuplot-info mailing list > gnu...@li... > Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info |
|
From: Mirko V. <mir...@gm...> - 2024-02-06 01:29:12
|
Thanks for replying. My answers are below On Sun, Feb 4, 2024 at 10:20 AM Peter Rockett via gnuplot-info < gnu...@li...> wrote: > Two questions: > > 1) Why do you want to send a SIGTERM to the process? Why isn't "exit" > (which you say works) good enough? The signal handler -- either the > default or an over-ridden version -- would typically invoke the system > call that actually shuts down the process. Which is probably what the > gnuplot "exit" command does one way or another. > You are correct that I really don't need to send SIGTERM. The reason is my testsuite which is in 3 layers: 1. Lifecycle 2. IO streams 3. sending commands and reading results I wanted the first layer of the test suite (lifecycle) to be independent of sending commands (last layer). I agree that this is somewhat of an overkill. But I was curious if it could be done. > 2) What OS are you using? Windows, for example, doesn't use signals - > they are a UNIX/Linux/MacOS(?) thing. I suspect sending a signal on > Windows will just be ignored, which is consistent with the behaviour you > seem to be observing. > I am on Windows 11 using gnuplot delivered via MSYS2. Since my original post, I learned that I can use taskkill to terminate processes. > > FWIW: The exact value of SIGTERM will be defined in a C header file > somewhere, probably "signals.h". > I did not find that file, but I did not look terribly hard. > > P. > Thanks, Mirko |
|
From: Peter R. <p.r...@sh...> - 2024-02-06 09:27:33
|
Bottom line here: If you are using Windows then the UNIX signals mechanism is not available. msys2 may provide a UNIX-like shell, but ultimately it sits atop Windows. The fact that you cannot find a signals.h file is entirely predictable. There will not be one. P. On 06/02/2024 01:28, Mirko Vukovic wrote: > Thanks for replying. My answers are below > > On Sun, Feb 4, 2024 at 10:20 AM Peter Rockett via gnuplot-info > <gnu...@li...> wrote: > > Two questions: > > 1) Why do you want to send a SIGTERM to the process? Why isn't "exit" > (which you say works) good enough? The signal handler -- either the > default or an over-ridden version -- would typically invoke the > system > call that actually shuts down the process. Which is probably what the > gnuplot "exit" command does one way or another. > > > You are correct that I really don't need to send SIGTERM. The reason > is my testsuite which is in 3 layers: > 1. Lifecycle > 2. IO streams > 3. sending commands and reading results > > I wanted the first layer of the test suite (lifecycle) to be > independent of sending commands (last layer). > > I agree that this is somewhat of an overkill. But I was curious if it > could be done. > > 2) What OS are you using? Windows, for example, doesn't use signals - > they are a UNIX/Linux/MacOS(?) thing. I suspect sending a signal on > Windows will just be ignored, which is consistent with the > behaviour you > seem to be observing. > > > I am on Windows 11 using gnuplot delivered via MSYS2. Since my > original post, I learned that I can use > taskkill to terminate processes. > > > FWIW: The exact value of SIGTERM will be defined in a C header file > somewhere, probably "signals.h". > > > I did not find that file, but I did not look terribly hard. > > > P. > > > Thanks, > > Mirko |
|
From: Robert D. <rob...@gm...> - 2024-02-06 17:52:12
|
On Sat, Feb 3, 2024 at 7:40 AM Mirko Vukovic <mir...@gm...> wrote: > I can shut down the process by sending the "exit" command. > > But I'd also like to send a signal (such as SIGTERM) to shut gnuplot down. Probably a cleaner and system independent way to tell gnuplot to shut down is just to close the socket through which commands are sent -- I don't know for sure, but I suspect that gnuplot will terminate if the socket is closed, since that is a widely used convention for organizing interprocess communications. Maxima (https://maxima.sourceforge.io) is a Common Lisp application and it has some code to work with gnuplot for plotting; see src/plot.lisp and src/gnuplot_def.lisp (I think those are the right file names) to get some ideas about how stuff was handled there. best, Robert |
|
From: Mirko V. <mir...@gm...> - 2024-02-07 00:24:41
|
On Tue, Feb 6, 2024 at 12:52 PM Robert Dodier <rob...@gm...> wrote: > On Sat, Feb 3, 2024 at 7:40 AM Mirko Vukovic <mir...@gm...> > wrote: > > > I can shut down the process by sending the "exit" command. > > > > But I'd also like to send a signal (such as SIGTERM) to shut gnuplot > down. > > Probably a cleaner and system independent way to tell gnuplot to shut > down is just to close the socket through which commands are sent -- I > don't know for sure, but I suspect that gnuplot will terminate if the > socket is closed, since that is a widely used convention for > organizing interprocess communications. > > Maxima (https://maxima.sourceforge.io) is a Common Lisp application > and it has some code to work with gnuplot for plotting; see > src/plot.lisp and src/gnuplot_def.lisp (I think those are the right > file names) to get some ideas about how stuff was handled there. > > Thanks Robert, I looked at the Maxima source in the src/plot.lisp, and your suggestion worked: Doing - with apologies for non-lisp readers that the parenthesis may confuse - (close (ccl:external-process-input-stream process-handle)) closes the process. `process-handle' is the structure returned by the command that launches gnuplot: (ccl:run-program "gnuplot" ...) Mirko |