LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-19-2011, 02:58 PM   #1
laredotornado
Member
 
Registered: Apr 2011
Posts: 71

Rep: Reputation: 0
Cleaning up this kill command


Hi,

Using Ubuntu 11.04. I use this command to kill frozen Flash processes ...

Code:
pgrep -P1 -f 'npviewer\.bin' | xargs kill -9
IF there are no hung processes, I get the error ...

Code:
Usage:
  kill pid ...              Send SIGTERM to every process listed.
  kill signal pid ...       Send a signal to every process listed.
  kill -s signal pid ...    Send a signal to every process listed.
  kill -l                   List all signal names.
  kill -L                   List all signal names in a nice table.
  kill -l signal            Convert between signal numbers and names.
Anyway I can prevent these errors from printing out if there are no matching processes? Thanks, - Dave

Last edited by laredotornado; 07-20-2011 at 08:19 AM.
 
Old 07-19-2011, 06:04 PM   #2
modonnell
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Rep: Reputation: 3
I have no problem with this so let's check a few things. For starters, find out what's actually being executed when you issue the "pgrep" command to the shell. Assuming you're using bash you could say:

type pgrep

...and on my machine it reports that when I say "pgrep" it would load /usr/bin/pgrep. If it instead reported some alias or shell script in some unexpected location we'd first want to take care of that. Sometimes your $PATH can be misconfigured such that some unexpected script or binary is being found and executed instead of the one you want.

Then find out what version you're running. On my system I can say this:

pgrep -V

...and it reports:

pgrep (procps version 3.2.8)

...which may or may not be similar to what you're running. If your version is dramatically older then you might want to try using your package manager to pull a newer version on board before spending too much time analyzing a pgrep bug that may already be fixed.

Last edited by modonnell; 07-19-2011 at 06:07 PM.
 
Old 07-20-2011, 08:20 AM   #3
laredotornado
Member
 
Registered: Apr 2011
Posts: 71

Original Poster
Rep: Reputation: 0
I just edited my post. I incorrectly listed the command that was giving that error. It is corrected now, but to repeat, it is

Code:
pgrep -P1 -f 'npviewer\.bin' | xargs kill -9
So the question is, if there is nothing piped into the "kill" command, can I get it to stop complaining? - Dave
 
Old 07-20-2011, 09:03 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
You are aware that pgrep comes with a sister command, "pkill", right? No need to bother with xargs.
 
Old 07-21-2011, 05:53 AM   #5
modonnell
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Rep: Reputation: 3
David the H. wrote:
Quote:
You are aware that pgrep comes with a sister command, "pkill", right? No need to bother with xargs.
...and that's likely the answer you want, of course. (I was getting to that! :-) But in keeping with your previous approach, this less elegant command would also work:

for pid in $(pgrep -P1 -f 'npviewer\.bin'); do kill -9 $pid; done

...which would do nothing when no matches are reported.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cleaning a usb disk with viruses using the command line ifranklin Linux - Software 5 10-26-2010 03:44 PM
kill command vinaytp Linux - Newbie 3 12-07-2009 10:01 PM
why we cannot kill process id 1 with command "kill -9 1" satyaredhat Linux - Newbie 7 03-11-2009 12:48 PM
kill command anipreeth Programming 2 12-14-2007 06:00 AM
Kill command could not kill Kanaflloric Linux - General 11 08-22-2005 07:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration