Skip to content

Instantly share code, notes, and snippets.

@skylens
Last active December 9, 2018 16:41
Show Gist options
  • Select an option

  • Save skylens/d4afb37809e45e0481c0a8aa0dfd0af0 to your computer and use it in GitHub Desktop.

Select an option

Save skylens/d4afb37809e45e0481c0a8aa0dfd0af0 to your computer and use it in GitHub Desktop.

Linux 下进程相关操作

查看进程号,进程名为 'name'

ps -ef | grep "name" | grep -v grep | awk '{print $2}'

ps -ef | awk '/[n]ame/{print $2}'

ps x | awk '/[n]ame/{print $1}'

pgrep -f name

shell 脚本

process-monitor.sh name

#!/bin/bash
# process-monitor.sh
process=$1
pid=$(ps x | grep $process | grep -v grep | awk '{print $1}')
echo $pid

杀死进程

pkill -f name
kill 进程号
pkill -9 name
killall -9 name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment