Ubuntu 终端:C 程序(或其他解决方案)来终止在特定端口上运行的进程并启动 xampp

Dra*_*n21 3 command-line c kill

谁能帮我?该程序的目标是杀死在端口 443 上运行的进程,然后xampp自动启动。

我所做的:

#include <stdio.h>
#include <stdlib.h>

main() {
    system("netstat -tulpn | grep :443");
    /* If 443 is busy (kill all)*/
    /*next -> */ system("/opt/lampp/xampp start");
}
Run Code Online (Sandbox Code Playgroud)

小智 6

要终止端口上的进程,您可以执行以下操作:

$ fuser -n tcp -k 443 && /opt/lampp/xampp start

更改&&;,如果你想它,如果有任何端口或不运行启动XAMPP不管。