LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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
Distribution: KUbuntu
Posts: 61

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
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
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,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
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
Distribution: KUbuntu
Posts: 61

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
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,342

Rep: Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746
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,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,342

Rep: Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746
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: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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
Distribution: KUbuntu
Posts: 61

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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:40 PM.

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