简体   繁体   English

如何在屏幕窗口中杀死bash文件运行的所有任务?

[英]How do I kill all tasks run by a bash file in a screen window?

Perhaps the answer is already out there, but after reading several Questions i didn't manage to do what I need. 也许答案已经存在,但在阅读了几个问题后,我无法做到我需要做的事情。

My situation: I am using a machine through ssh . 我的情况:我通过ssh使用机器。 I created a screen window, I called a bash file like the following: 我创建了一个screen窗口,我调用了一个bash文件,如下所示:

for var in 1..N
do
java -option $var
done

with N very high. N非常高。

Question: Is there a way to kill the all the java tasks launched by the bash file at once? 问题:有没有办法一次性杀死bash文件启动的所有java任务? Or to kill the screen window and everything is running in the screen? 或者杀死屏幕窗口,一切都在屏幕上运行?

Note : The java tasks are running -inside the screen - in the foreground. 注意java任务正在运行 - 在screen - 在前台。 If I try to do CTRL-C I can kill only one java task at the time. 如果我尝试做CTRL-C我当时只能杀死一个java任务。

  1. Find out the process ID of the screen session. 找出屏幕会话的进程ID。
  2. Use this pid number to kill screen and all its child processes 使用此pid编号可以终止屏幕及其所有子进程

For example: 例如:

Put screen in the background ( Ctrl-Alt + D ) screen放在后台( Ctrl-Alt + D

List your open screen sessions: 列出您的开放屏幕会话:

screen -ls

You'll get something like: 你会得到类似的东西:

There is a screen on:
    2222.pts-3.yourmachine    (Detached)

The first number is the process ID of the screen session. 第一个数字是屏幕会话的进程ID。

Use this number to kill the screen and all its childs: 使用此数字可以杀死屏幕及其所有子节点:

PID=2222
kill $PID

If your java application catches some signals, use a less graceful way to kill them, eg kill -9 $PID 如果您的java应用程序捕获一些信号,请使用不太优雅的方法来杀死它们,例如kill -9 $PID

如果你不害怕杀死任何正在运行的java进程你可以做总是有用的“killall -9 java”:)

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

相关问题 如何在Java中的所有其他任务之前运行语音识别器,使得只有在输出包含开始的情况下,程序才能继续 - How do I run speech recognizer before all other tasks in Java, in such a way that only if the output contains begin, the program continues 在Java中,我如何等待所有任务,但在第一个错误时停止? - In Java, how do I wait for all tasks, but halt on first error? 如何编写 bash 脚本来运行导入 maven 依赖项的 java 文件? - How do I write a bash script to run a java file that imports maven dependices? 如何让我的 jar 文件打开一个终端窗口来运行其他类? - How do I make my jar file open a terminal window to run other class? 如何在 Java 中将窗口大小调整为全屏? - How do I resize a window to full screen in Java? "如何在终端中杀死这个 tomcat 进程?" - How do I kill this tomcat process in Terminal? 如何在等待时杀死线程? - How do I kill a thread on wait? 如何杀死在线程中运行的 Runnable? - How do I kill a Runnable running in a Thread? 如何使用Swing运行后台任务? - How can I run background tasks with Swing? 一小时后如何在不知道特定的PID的情况下杀死特定的Java文件? - How do I kill a specific java file after one hour, without knowing it's specific PID?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM