LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 02-19-2013, 12:13 PM   #1
MarkoSan
Member
 
Registered: Jun 2006
Location: Ljubljana
Posts: 57

Rep: Reputation: 1
ps command question


Hi to all!

I just wonder something: Let say I use ps command to list all processes in a fashion:
Quote:
ps -A|grep "konsole"
If "konsole" process is running it is displayed along with its pid. How would I extend command usage so it can kill the process, which name is parameter and not pid?

Sincerely,
Marko
 
Old 02-19-2013, 12:18 PM   #2
273
Senior Member
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64&i386, Raspbian Jessie, various VMs
Posts: 3,161

Rep: Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729
For that I believe you want pkill.
 
Old 02-19-2013, 12:19 PM   #3
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,565

Rep: Reputation: 410Reputation: 410Reputation: 410Reputation: 410Reputation: 410
So you just want to kill all the processes with the name of "konsole"?

Code:
pkill -15 konsole
 
1 members found this post helpful.
Old 02-19-2013, 11:23 PM   #4
MarkoSan
Member
 
Registered: Jun 2006
Location: Ljubljana
Posts: 57

Original Poster
Rep: Reputation: 1
Thank you very much, but I want to make a script on my own!

Sincerely,
Marko
 
Old 02-19-2013, 11:34 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,225

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
If you mean what I think, use awk to get the pids, then loop through and kill, or pipe to kill
eg
Code:
ps -A|grep konsole |awk '{print $1}'
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
Old 02-19-2013, 11:55 PM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
Why not use pgrep?
Code:
~$ for pid in $(pgrep konsole); do kill -9 $pid; done
OR, in script form:

Code:
#!/bin/bash
for pid in $(pgrep konsole)
do
kill -9 $pid
done

Last edited by shivaa; 02-19-2013 at 11:56 PM.
 
Old 02-20-2013, 12:16 AM   #7
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,225

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
As per post #4, it seems he wants to do it the long way around; possibly a homework thing?
 
Old 02-21-2013, 06:17 PM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,944
Blog Entries: 54

Rep: Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731
FWIW this:
Code:
ps -A|grep konsole |awk '{print $1}'
equals that:
Code:
ps --noheaders -C konsole -opid
 
1 members found this post helpful.
Old 02-22-2013, 12:00 AM   #9
MarkoSan
Member
 
Registered: Jun 2006
Location: Ljubljana
Posts: 57

Original Poster
Rep: Reputation: 1
Thank you all very much! Will carefully analyze your posts (was absent), it is not a homework, I am just being curious!

Sincerely,
Marko
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about the dd command kaplan71 Linux - Software 5 04-09-2010 08:09 AM
mt command question Ayman.mashal Linux - General 3 06-17-2005 05:19 AM
Command question satimis Fedora 3 04-04-2005 12:24 AM
cp command question satimis Linux - Newbie 1 09-13-2003 08:31 PM
SU command question downinthemine Linux - Newbie 25 07-31-2003 08:21 PM


All times are GMT -5. The time now is 06:36 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration