简体   繁体   English

如何杀死在服务器上运行的进程

[英]How to kill a process running on server

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. 我使用run_command shell程序在客户端机器上的服务器上运行一些命令,这个shell程序通过套接字通信在服务器上运行特定命令。 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. 在服务器端我使用java程序在服务器上运行命令,通常对于像ls这样的命令, pwd它运行良好,但是对于像"tail -f"这样的命令,虽然我按ctrl^c来停止命令,但它并没有停止在服务器端。

  1. is there any way to to capture ctrl^c so that i will send some msg that kills running command on server 是否有任何方法来捕获ctrl ^ c,以便我将发送一些消息在服务器上杀死运行命令

  2. to kill some command on server , how can i kill only that particular command which was run from client not any other 要杀死服务器上的一些命令,我​​怎么能只杀死从客户端运行的特定命令而不是任何其他命令

Use kill command. 使用kill命令。 For more information please refer URL Kill Command for UNIX 有关更多信息,请参阅UNIX的 URL Kill Command

first of all, I assume that for some reason you cannot run kill on that run_command thing. 首先,我假设由于某种原因你无法在run_command事件上运行kill。 If you can, ignore below answer. 如果可以,请忽略以下答案。

On the server, start Process. 在服务器上,启动Process。 Wrap the Process object along with an ID (auto generated). 将Process对象与ID(自动生成)一起包装。 Add wrapper to a List or Map. 将包装器添加到List或Map。 Display the ID to user on client. 在客户端上向用户显示ID。

when user wants to kill process, send something like "mykill ". 当用户想杀死进程时,发送类似“mykill”的内容。 On server, if command.equals("mykill"), then get the Process indicated by id and call its destroy method, and remove from list. 在服务器上,如果是command.equals(“mykill”),则获取id指示的进程并调用其destroy方法,并从列表中删除。 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. 我使用run_command shell程序在客户端机器上的服务器上运行一些命令,这个shell程序通过套接字通信在服务器上运行特定命令。

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. 我只是在提出想法。

也许你正在寻找这个

killall `pidof ProcessName` 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM