pid를 구하여 프로세스 kill을 할려고 하는데 여러개일 경우가 문제입니다.

dcmru의 이미지

구동스크립트를 만들었는데, stop시 문제가 있습니다.

proc=test
pid=`/bin/ps -e | grep ' test$' | sed -e 's/^ *//' -e 's/ .*//'`
echo "Stopping $prog."
if [ "${pid}" != "" ]; then
kill ${pid} > /dev/null 2>&1
fi

이렇게 했는데, 같은 이름의 프로세스가 여러개 있을 경우 제일 처음 pid만 kill을 합니다.

같은 이름의 프로세스를 모두 죽일려면 어떻게 해야하나요?

아니면 실제 데몬의 pid만 구할 수 있는 방법이 있는지요?

Linux이면 killall test 를 하면될것 같은데, 다른 OS에서 문제가 있을 것 같습니다.

어떤방법이 있을까요?

ironiris의 이미지

pkill 이라는 프로그램이 있습니다.
솔라리스에서도 기본인 프로그램 같더군요.
안녕리눅스에도 있고.. centos 에도 있고.. 다 있나본데요? ^^;

dary4n의 이미지

pidof 만 주로 썼는데 pkill 좋네요. ^_^

---
사람의 기쁨이나 슬픔 같은 것은...
풀꽃의 희미한 향기만큼도 오래 지속되지 않는다...

---
사람의 기쁨이나 슬픔 같은 것은,
풀꽃의 희미한 향기만큼도 오래 지속되지 않는다.

dary4n의 이미지

pids=$(ps -e | grep 'test' | grep -v grep| awk '{print $1}')

이렇게 하시거나,

리눅스 root 유저라면 pidof test 등으로 프로세스 잡으시면 됩니다.

---
사람의 기쁨이나 슬픔 같은 것은...
풀꽃의 희미한 향기만큼도 오래 지속되지 않는다...

---
사람의 기쁨이나 슬픔 같은 것은,
풀꽃의 희미한 향기만큼도 오래 지속되지 않는다.

SoulreaveR의 이미지

원츄

lovian의 이미지

무식하게,
for 문을 돌립니다! -_-a
-----------------
한글을 사랑합니다.

-----------------
한글을 사랑합니다.

dcmru의 이미지

알려주신 것으로 테스트해봐야겠습니다. ^^

여러 OS를 대상으로 하기 때문에 없는 명령어도 있습니다.

그리고 그냥 kill 로 옵션없이 실행했더니 프로세스가 잘 안죽는 군요.

-9 옵션을 써도 무방할까요?

----------------------------------------------
노력만이 살길이다.

노력만이 살길이다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.