LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Killing a plink process

Hi all. I'm using putty (more precisely PLink.exe) to establish a secure SSH connection with a server for a LV application I'm building.
I can successfully call plink using the System Exec function. However, I can't work out a way to kill it afterwards. The application will need to close the session of plink and relaunch it occassionally with different configurations. But to do this I need to close the running session before i can relaunch it. System Exec.vi does not return a useable reference for the plink session to allow any kind of control over it, so I can't, for example, send a "CTRL-C" to the session to kill it.
Anybody know of a way to kill a running process called by System Exec?
Can I get a list of running processes somehow, and search for 'plink', then 'kill' those identified sessions?
Any help will be most appreciated! Smiley Happy
Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 1 of 15
(10,435 Views)


Thoric wrote:

Anybody know of a way to kill a running process called by System Exec?

You can kill a process using the Windows taskkill command.

___________________
Try to take over the world!
0 Kudos
Message 2 of 15
(10,428 Views)
Thanks for this. Presumably I could simple call:
taskkill /im plink.exe
to kill any running plink processes.
But what I'd really like is a method to return a process ID from System Exec to the exact running session of plink so that I know I'm killing the right process. There may be other running sessions of plink that my application ought to leave alone, so simply killing them all could be a bad idea.

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 3 of 15
(10,413 Views)
Have a look at this thread.
 
\RayR
Message 4 of 15
(10,407 Views)
RayR - I must be missing something, I don't how this is different to what was suggested already by TST? Your suggested thread seems to discuss an NI document that uses TaskKill to kill a running task (as did TST), but unless I can get a process ID from System Exec, how can I be sure I'm killing the correct process? I can't use the process name, as there may be a handful of these processes and I need to kill only the one launched by the LV app. Please advise Smiley Happy


Message Edited by Thoric on 06-20-2008 01:50 PM
Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 5 of 15
(10,399 Views)


Thoric wrote:
Thanks for this. Presumably I could simple call:
taskkill /im plink.exe
to kill any running plink processes.
But what I'd really like is a method to return a process ID from System Exec to the exact running session of plink so that I know I'm killing the right process. There may be other running sessions of plink that my application ought to leave alone, so simply killing them all could be a bad idea.



I had not seen this reply when I wrote mine.  (Read the one from tst, looked for & provided a link to it...  got distracted, and  then clicked submit reply a few minutes later...  sorry)
 
I see the problem..  You may have multiple instances of plink.exe running at the same time.  Wow..  I'm not sure how you would distinguish between them..  However, Windows must keep track of each instance...  And even if you had access to that information, could you actually kill that particular one?  That part I do not know how to do.. 😞 
RayR
Message 6 of 15
(10,390 Views)
Thanks for the optimistic outlook RayR Smiley Very Happy

I've had to reach a compromise, and this is what I've done (for anyone whose interested):

For each occasion when I want to launch plink, I first make a local copy of the executable with a slightly different name (something like plinkaa.exe for example).
When I lauch it with System Exec I set the function flag Wait Until Done to false to make sure I'm not hanging around for it to finish (cos it won't), nd this launches plink as plinka.exe, which is very likely to be a unique name.

Later, when I want to kill the relevant process, I generate a list of running process names and IDs using the .NET extensions found in the NI example (LabVIEW 8.5\examples\comm\dotnet\SimpleTaskMonitor).
I search the name array for plinkaa (no .exe suffix!), and use the index result to find the process ID from the ID list array. Then I use a similar .NET property node to kill the process (scroll down the property list and you'll see KILL). This kills the specific plink process.

Not very professional, but it does the job. And as long as you pick a relatively unique name (but not so obscure that a user would panic if they saw the process in Task Manager should they go looking) then there's very little chance that the process you are killing is anything but the one you launched.

I'd welcome any input from anyone regarding improvements to this? A way to call WinAPI.dll to launch an executable and return the process ID perhaps??
Thoric (CLA, CLED, CTD and LabVIEW Champion)


Message 7 of 15
(10,384 Views)
(spell checked version!)
Thanks for the optimistic outlook RayR Smiley Very Happy

I've had to reach a compromise, and this is what I've done (for anyone whose interested):

For each occasion when I want to launch plink, I first make a local copy of the executable with a slightly different name (something like plinkaa.exe for example).
When I launch it with System Exec I set the function flag Wait Until Done to false to make sure I'm not hanging around for it to finish (cos it won't), and this launches plink as plinkaa.exe, which is very likely to be a unique name.

Later, when I want to kill the relevant process, I generate a list of running process names and IDs using the .NET extensions found in the NI example (LabVIEW 8.5\examples\comm\dotnet\SimpleTaskMonitor).
I search the name array for plinkaa (no .exe suffix!), and use the index result to find the process ID from the ID list array. Then I use a similar .NET property node to kill the process (scroll down the property list and you'll see KILL). This kills the specific plink process.

Not very professional, but it does the job. And as long as you pick a relatively unique name (but not so obscure that a user would panic if they saw the process in Task Manager should they go looking) then there's very little chance that the process you are killing is anything but the one you launched.

I'd welcome any input from anyone regarding improvements to this? A way to call WinAPI.dll to launch an executable and return the process ID perhaps??


Message Edited by Thoric on 06-20-2008 03:52 PM
Thoric (CLA, CLED, CTD and LabVIEW Champion)


Message 8 of 15
(10,378 Views)
That's when workarounds are useful!  😄
 
It didn't even cross my mind this morning.  Must be because of 2 weeks of rain!  LOL! 😄
 
Thanks for sharing the info!
 
RayR
Message 9 of 15
(10,375 Views)

Thanks for sharing your solution Thoric! I have recently come across the need to do something similar myself.

 

I was considering something slightly different. Just before starting the plink.exe process, readout the output from 'tasklist' using System Exec, and then check if there are any active plink.exe processes running and note the PIDs for them. Then right after starting the plink.exe process check the output from 'tasklist' again using System Exec for any new PIDs for plink.exe. Based on the speed of the operation you should usually be able to determine the PID of the process you started. And then later use that to kill it. Just a slightly different workaround to the problem.

0 Kudos
Message 10 of 15
(7,820 Views)