Sponsored Content
Full Discussion: Find PID for a process
Top Forums Shell Programming and Scripting Find PID for a process Post 302493365 by methyl on Wednesday 2nd of February 2011 01:20:55 PM
Old 02-02-2011
Quote:
PROCESS_PID=`ps -ef | grep processname | awk '{print $2}'`
kill -9 $PROCESS_PID
Hmm. Third time this week.
Please avoid issuing "kill -9" it is really the last resort and bypasses normal process cleanup.
The above script is too dangerous to run on any system as "root" because it can make accidental or multiple matches and potentially crash your system.
Also there are different syntaxes for "ps" depending on the Operating System.

Please post sample "ps" output of the process concerned and more detail of what the process does and why you need to kill it.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Process PID

Hi Friends :p I have a little problem please help me out. I have a Unix based OS Sun Server having oracle 8i as database on it. The server has one client with windows OS. The client uses developer 2000 (GUI) to run query and run processes. I want to know how can I know the PID of a process run... (3 Replies)
Discussion started by: vanand420
3 Replies

2. Solaris

getting pid of process

hi all, Is there a simple script anyone could through out to me, to find the pid of a process given the name. I actually need to bind this pid to a processor set. I would probably put these comamns in a shell script which would have. a) kick start the executable b) get the pid c) bind it to a... (10 Replies)
Discussion started by: Naanu
10 Replies

3. UNIX for Dummies Questions & Answers

Need to get pid of a process and have to store the pid in a variable

Hi, I need to get the pid of a process and have to store the pid in a variable and i want to use this value(pid) of the variable for some process. Please can anyone tell me how to get the pid of a process and store it in a variable. please help me on this. Thanks in advance, Amudha (7 Replies)
Discussion started by: samudha
7 Replies

4. UNIX for Dummies Questions & Answers

How to find the details of the previously running process with PID

OS: Unix or Linux I (only) know the pid of the process which was running earlier (say 5 hrs back) but it is not running now. Is there a way I could find the details of that process? (atleast the name of the process). Please let me know. (2 Replies)
Discussion started by: vijay.d
2 Replies

5. Shell Programming and Scripting

Find shell process pid launched throug `at`.

Hi. I was testing some staff and wrote simple script, which only writes date to log every 15 seconds. Like that #1.sh while true;do echo `date` >> 1.log sleep 15 done And than i ran this process with `at -s -f 1.sh now`. And now it is running and i don't know how to catch it. I tryed... (1 Reply)
Discussion started by: kukuruku
1 Replies

6. Programming

[C] Process pid by name

Hi I use linux OS. I've already written a function that allow me to get the process name by pid. (searching in /proc). Now I'd like to perform the inverse task.I mean get the process pid by its name. I could write a function that search in every folder in /proc for the process name, but i... (2 Replies)
Discussion started by: Dedalus
2 Replies

7. Shell Programming and Scripting

find pid of process run in specific location

Hello, I have a process a.out that runs from /a and /b How can I get the pid of the one running from /a ps -C /a/a.out does not work Thanks! (4 Replies)
Discussion started by: JCR
4 Replies

8. Solaris

how to find PID of a runnign process ?

Hi Friends, How can we find the process ID of a running process using the process name. In AIX I used to use the command "ps -ef | grep <process name>", it used to give me the owner of that process, Process ID and the threads running and the name of the process in the end. However in... (2 Replies)
Discussion started by: sahilsardana
2 Replies

9. UNIX for Dummies Questions & Answers

Help with simple script to find PID of process

Hi everyone. I've been reading around and am a little bit overwhelmed, hoping to find a kind soul out there to hold my hand through writing my first script. This need has emerged at work and I haven't much experience writing shell scripts, but this is a problem we have with a production environment... (13 Replies)
Discussion started by: thirdcoaster
13 Replies

10. Shell Programming and Scripting

Find the Pid and Kill the Process after a Few Minutes

hi guys i had written a shell script Display Information of all the File Systems i want to find the pid and kill the process after few minutes.how can i obtain the pid and kill it??? sample.sh df -a >> /tmp/size.log and my cron to execute every minute every hour every day * *... (5 Replies)
Discussion started by: azherkn3
5 Replies
kill(2) 							System Calls Manual							   kill(2)

NAME
kill - Sends a signal to a process or to a group of processes SYNOPSIS
#include <signal.h> int kill( pid_t process, int signal ); Application developers may want to specify an #include statement for <sys/types.h> before the one for <signal.h> if programs are being developed for multiple platforms. The additional #include statement is not required on Tru64 UNIX systems or by ISO or X/Open standards, but may be required on other vendors' systems that conform to these standards. STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: kill(): XSH5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Specifies the process or group of processes. Specifies the signal. If the signal parameter is a value of 0 (the null signal), error check- ing is performed but no signal is sent. This can be used to check the validity of the process parameter. DESCRIPTION
The kill() function sends the signal specified by the signal parameter to the process or group of processes specified by the process param- eter. To send a signal to another process, at least one of the following must be true: The real or the saved set-user-ID of the sending process matches the real or effective user ID of the receiving process. The process is trying to send the SIGCONT signal to one of its session's processes. The calling process has root privileges. Processes can send signals to themselves. Sending a signal does not imply that the operation is successful. All signal operations must pass the access checks prescribed by each enforced access control policy on the system. If the process parameter is greater than 0 (zero), the signal specified by the signal parameter is sent to the process that has a process ID equal to the value of the process parameter. If the process parameter is equal to 0 (zero), the signal specified by the signal parameter is sent to all of the processes (other than system processes) whose process group ID is equal to the process group ID of the sender. If the process parameter is equal to -1, the signal specified by the signal parameter is sent to all of the processes other than system processes for which the process has permission to send that signal. For example, if the effective user ID of the sender has root privi- leges, the signal specified by the signal parameter is sent to all of the processes other than system processes. If the process parameter is negative but not -1, the signal specified by the signal parameter is sent to all of the processes which have a process group ID equal to the absolute value of the process parameter. RETURN VALUES
Upon successful completion, the kill() function returns a value of 0 (zero). Otherwise, a value of -1 is returned and errno is set to indi- cate the error. NOTES
Some applications and scripts depend on the process ID of the init program being 1 (one): do not depend on it. Instead, use standard methods, such as the ps and grep commands, to obtain all process IDs. ERRORS
The kill() function sets errno to the specified values for the following conditions: The signal parameter is not a valid signal number. [Tru64 UNIX] The signal parameter is SIGKILL, SIGSTOP, SIGTSTP or SIGCONT and the process parameter is the process ID of the init program. No process or process group can be found corresponding to that specified by the process parameter. The real or saved user ID does not match the real or effective user ID of the receiving process, the calling process does not have appropriate privilege, and the process is not sending a SIGCONT signal to one of its session's processes. [Tru64 UNIX] The calling process does not have appropriate privilege. RELATED INFORMATION
Functions: getpid(2), killpg(2), raise(3), setpgid(2), sigaction(2), sigvec(2) Standards: standards(5) delim off kill(2)
All times are GMT -4. The time now is 11:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy