2011-01-04 1 views
13

저는 매분마다 "ar_sendmail"(ARmailer에서)이라는 프로세스를 시작하기 위해 스케줄러 (Rufus scheduler)를 사용합니다.Ruby에서 실행중인 프로세스를 확인하는 방법은 무엇입니까?

메모리를 다 소모하지 않도록 프로세스가 이미 실행 중이면 프로세스를 시작해서는 안됩니다.

이 프로세스가 이미 실행되고 있는지 어떻게 확인합니까? 아래 unless 뒤에 오는 것은 무엇입니까?

scheduler = Rufus::Scheduler.start_new 

    scheduler.every '1m' do 

    unless #[what goes here?] 
     fork { exec "ar_sendmail -o" } 
     Process.wait 
    end 

    end 

end 

답변

23
unless `ps aux | grep ar_sendmai[l]` != "" 
+0

감사합니다! 1 질문 뒤로 : 왜 "ar_sendmail"의 "l"주위에 괄호가 있습니까? – TomDogg

+8

ar_sendmail과 일치하는 프로세스에 대해 grep에서 호출 프로세스를 제거합니다. 그렇지 않으면 'grep ar_sendmail'에 대한 결과를 얻습니다. – stef

+0

Muchas gracias, señor! – TomDogg

8
unless `pgrep -f ar_sendmail`.split("\n") != [Process.pid.to_s] 
+1

호출 프로세스를 제외하기 위해 브래킷을 사용할 필요가 없으므로 이것이 훨씬 더 나은 해결책이라고 생각합니다. – while

+0

편집 : pgrep의 반환 구조 때문에 분할이 필요합니다. – dahlberg