-
On Linux, you can use
pidof -
On MacOS, try
ps -ax | grep -m1 <process-name> | awk '{print $1}'
-
ps -aux: 查看进程状态parameter function -a显示所有用户有终端控制的进程 -u显示用户以及其他详细信息 -x显示没有控制终端的进程 - ps 允许省略参数前的
-:ps aux
- ps 允许省略参数前的
kill $(lsof -t -i :PORTNUMBER)Linux:
netstat -tunlp | grep 8080The closest equivalent you can get on macOS is:
netstat -p tcp -van | grep '^Proto\|LISTEN' | grep 8080Or use lsof (list opened files)
sudo lsof -i:8080NOTE: lsof just list files opened by current users, you need add sudo if you want to see all opened files.
#!/bin/sh
echo “1”
sleep 5&
echo “3”
echo “4”
wait #会等待wait所在bash上的所有子进程的执行结束,本例中就是sleep 5这句
echo”5”NOTE: the last ; is key important to Linux
{ command1 && command2 ; } > dist.file- solution1: ssh one line command
ssh 192.168.171.161 "uptime;hostname" - solution2: if the job is complex, add
bashcommand to suppress Pseudo-terminal warningssh 192.168.171.161 bash <<EOF uptime hostname EOF