如何从 Java GUI 运行和终止 Fedora 中的进程

发布于 2024-08-24 10:04:20 字数 229 浏览 4 评论 0原文

我在 Fedora 工作。我想用 Java 创建一个带有两个按钮的 GUI:开始和停止。我有两个进程:p1 和 p2。当我单击“开始”时,p1 应在后台运行,p2 应在前台运行。 (在终端中,我们通过给出 ./p1./p2 来完成此操作。)当我单击“停止”时,这两个进程都应该被终止。 (等效的终端是:CTRL+C 和kill -9 pid)。

谁能建议如何做到这一点?

I'm working in Fedora. I want to create a GUI in Java with two buttons: START and STOP. I have two processes: p1 and p2. When I click on START, p1 should run in the background and p2 should run in the foreground. (In the terminal, we do this by giving ./p1 and ./p2.) When I click on STOP, both the processes should be killed. (The terminal equivalent is: CTRL+C and kill -9 pid).

Can anyone suggest the way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梨涡 2024-08-31 10:04:20

正如评论中指出的,在 java 中,您可以使用 Process 和 ProcessBuilder API 来启动其他进程。

以下链接指向相关 API 文档:
http://docs.oracle.com/ javase/1.5.0/docs/api/java/lang/Process.html
http://docs.oracle.com/ javase/1.5.0/docs/api/java/lang/ProcessBuilder.html

根据 API 文档,您可以启动进程,向其传递命令行参数和环境变量,访问其输入和输出流并终止进程他们。

Stack Overflow 上还有几个相关问题可能会有所帮助,例如 这个

As pointed out in the comments, in java you can use the Process and ProcessBuilder API's to start other processes.

The following links point to relevant API documentation:
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Process.html
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/ProcessBuilder.html

According to the API docs, you can start processes, pass command line arguments and environment variables to them, access their input and output streams and kill them.

There are also several related questions here on Stack Overflow that may be able to help e.g. this one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文