Reputation: 267
I am using run_command shell program to run some commands on servers from client machine, this shell program runs particular command on server by socket communication. In Server side i use java program to run command on server, Normally for commands like ls , pwd
it is working good , but for commands like "tail -f"
though i am pressing ctrl^c
to stop a command, it is not stopping in server side.
is there any way to to capture ctrl^c so that i will send some msg that kills running command on server
to kill some command on server , how can i kill only that particular command which was run from client not any other
Upvotes: 0
Views: 3226
Reputation: 1633
first of all, I assume that for some reason you cannot run kill on that run_command thing. If you can, ignore below answer.
On the server, start Process. Wrap the Process object along with an ID (auto generated). Add wrapper to a List or Map. Display the ID to user on client.
when user wants to kill process, send something like "mykill ". On server, if command.equals("mykill"), then get the Process indicated by id and call its destroy method, and remove from list. Also remove stale processes from your list (whether running or exited, just to keep your list or map from getting too big).
I am using run_command shell program to run some commands on servers from client machine, this shell program runs particular command on server by socket communication.
I assume there is a good reason you are not using putty. I also assume you can modify the code of that server.
Please note I have not tried this myself. I am just giving ideas.
Upvotes: 1
Reputation: 217
Use kill command. For more information please refer URL Kill Command for UNIX
Upvotes: 1