"리눅스 프로세스 이름으로 PID 알아내기"의 두 판 사이의 차이

6번째 줄: 6번째 줄:
;명령어
;명령어
<source lang='bash'>
<source lang='bash'>
ps -ef | grep 프로세스이름
ps -ef | grep 프로세스명
</source>
</source>


;실행 예시
;실행 예시
<source lang='dos'>
<source lang='dos'>
[root@localhost ~]# ps -ef | grep top
[root@localhost ~]# ps -ef | grep tail
root    25285 25219  0 20:24 pts/0    00:00:00 top
root    25387 25219  0 20:32 pts/0    00:00:00 tail -f /var/log/messages
root    25326 25288  0 20:24 pts/1    00:00:00 grep top
root    25390 25288  0 20:32 pts/1    00:00:00 grep tail
</source>
위에서 프로세스명이라고는 했지만 실제로는 출력내용 중 해당 문자열이 포함된 행을 찾는 것이다. 따라서 실행명령어(예: messages) 내용으로 찾을 수도 있다.
 
<source lang='dos'>
[root@localhost  ~]# ps -ef | grep messages
root    25387 25219  0 20:32 pts/0    00:00:00 tail -f /var/log/messages
root    25420 25288  0 20:37 pts/1    00:00:00 grep messages
</source>
</source>


26번째 줄: 33번째 줄:
;실행 예시
;실행 예시
<source lang='dos'>
<source lang='dos'>
[root@localhost ~]# ps -ef | grep top | grep -v grep
[root@localhost ~]# ps -ef | grep tail | grep -v grep
root    25285 25219  0 20:24 pts/0    00:00:00 top
root    25387 25219  0 20:32 pts/0    00:00:00 tail -f /var/log/messages
</source>
</source>


37번째 줄: 44번째 줄:
;실행 예시
;실행 예시
<source lang='dos'>
<source lang='dos'>
[root@localhost ~]# PID=`ps -ef | grep top | grep -v grep | awk '{print $2}'`
[root@localhost ~]# PID=`ps -ef | grep tail | grep -v grep | awk '{print $2}'`
[root@localhost ~]# echo $PID
[root@localhost ~]# echo $PID
25285
25387
</source>
</source>


[[분류:리눅스]]
[[분류:리눅스]]

2012년 3월 1일 (목) 20:39 판

  • 프로세스 이름으로 프로세스 ID 알아내기

1 방법 1

가장 간단한 방법이지만, grep 프로세스 자신도 출력된다.

명령어
ps -ef | grep 프로세스명
실행 예시
[root@localhost ~]# ps -ef | grep tail
root     25387 25219  0 20:32 pts/0    00:00:00 tail -f /var/log/messages
root     25390 25288  0 20:32 pts/1    00:00:00 grep tail

위에서 프로세스명이라고는 했지만 실제로는 출력내용 중 해당 문자열이 포함된 행을 찾는 것이다. 따라서 실행명령어(예: messages) 내용으로 찾을 수도 있다.

[root@localhost  ~]# ps -ef | grep messages
root     25387 25219  0 20:32 pts/0    00:00:00 tail -f /var/log/messages
root     25420 25288  0 20:37 pts/1    00:00:00 grep messages

2 방법 2

방법1에서 grep 프로세스 제외시킨다.

명령어
ps -ef | grep 프로세스명 | grep -v grep
실행 예시
[root@localhost  ~]# ps -ef | grep tail | grep -v grep
root     25387 25219  0 20:32 pts/0    00:00:00 tail -f /var/log/messages

3 PID 변수에 담기

PID=`ps -ef | grep 프로세스명 | grep -v grep | awk '{print $2}'`
실행 예시
[root@localhost ~]# PID=`ps -ef | grep tail | grep -v grep | awk '{print $2}'`
[root@localhost ~]# echo $PID
25387
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}