#!/bin/bash

function _get_pid_by_bin() {
	echo $1
    local bin="$1"                     # 参数：程序文件路径或名称
    local rbin
    rbin="$(readlink -f "$bin" 2>/dev/null)" || return 1
	echo "aaa" $rbin "bbb"

    # 遍历所有匹配名称的进程
    for pid in $(pgrep -f "$(basename "$bin")"); do
        local exe
        exe="$(readlink -f "/proc/$pid/exe" 2>/dev/null || true)"
        if [[ "$exe" == "$rbin" ]]; then
            echo aaa"$pid"
        fi
    done
}

echo "start"
pid=_get_pid_by_bin /root/xray/hysteria-linux-amd64
echo "pid:" $pid