shell command to find a process id and attach to it?

前端 未结 6 1756
感动是毒
感动是毒 2021-01-14 14:04

I want to attach to a running process using \'ffffd\', what I manually do is:

# ps -ax | grep PROCESS_NAME

Then I get a list and the pid, the

6条回答
  •  Happy的楠姐
    2021-01-14 14:24

    You can use awk to both filter and get the column you want. The "exit" limits the ps results to the first hit.

    function ffffd_grep() {
      ffffd $(ps -ax | awk -v p="$1" '$4 == p { print $1; exit 0; }');
    }
    
    ffffd_grep PROCESS_NAME
    

    You may have to adjust the columns for your ps output. Also you can change the == to ~ for regex matching.

提交回复
热议问题