Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 08-14-2006, 06:21 AM   #1
Registered: Jul 2006
Posts: 41

Rep: Reputation: 15

HiI want to kill a process that may be either in sleeping or executing mode.I am trying to get the pid of the program (which is also a bash script) by "pidof" but the shell responds:
-bash: pidof: command not found ( even though it exists in the man pages) when I call
kill $(pidof -x statuscontrol) where statuscontrol is the name of my shell script.
so is there another way to get the pid of the program?(in sleeping or executing state)Also can it be a problem that the program gets into executing mode from sleeping mode when at that moment kill command executes?Thank u very much..
Old 08-14-2006, 06:41 AM   #2
Registered: Apr 2006
Location: holland
Distribution: Gentoo / debian / suse / mint
Posts: 558

Rep: Reputation: 42
pidof requires the full path to the script or program. so it'd be something like: pidof /usr/bin/statuscontrol

Then it should find the PID. Works for me .
Old 08-14-2006, 07:14 AM   #3
Registered: Jul 2006
Posts: 41

Original Poster
Rep: Reputation: 15
Thank u for your answer bu I am afraid the full path of the program will change from time to time and searching each time will not be so efficient for a huge linux file system.(this script will run on such).I thought ps | grep <progname> | cut -c1-6 could do but I think that will be wrong too because PID character size can vary.(does it ??)so ı need to cut the first string
in such a line "26398 pts/0 00:00:00 ps".(until the first whitespace character) to just get 26398 .I am sorry ,I think I ask too primitive questions but I'm new at grouping the commands with neccessary options
Old 08-14-2006, 07:33 AM   #4
Registered: Jul 2006
Posts: 41

Original Poster
Rep: Reputation: 15
I think ps | grep <progname> |awk '{print $1}' will work
Old 08-14-2006, 09:34 AM   #5
Registered: Sep 2004
Location: Malaysia, Johor
Distribution: Dual boot MacOS X/Ubuntu 9.10
Posts: 851

Rep: Reputation: 31
or this command will do
#ps -aux |grep programname | grep -v grep
Old 08-14-2006, 09:40 AM   #6
Senior Member
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
take a look at pgrep and pkill. they allow you to find and kill processes based on other attributes (such as name etc.).


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
What if 'kill -9' fails to kill a task? chii-chan Linux - Newbie 15 03-27-2013 03:47 PM
how to use kill to kill a batch of processes with same name? dr_zayus69 Linux - Software 2 09-03-2005 06:35 PM
Kill command could not kill Kanaflloric Linux - General 11 08-22-2005 07:18 AM
cannot kill process (kill -9 does not work) mazer13a Linux - General 1 05-27-2005 02:32 PM
kill X = kill computer! jd243 Slackware 3 07-01-2003 11:29 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:26 PM.

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