What is my script's process ID ... ???


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting What is my script's process ID ... ???
# 1  
Old 09-18-2010
What is my script's process ID ... or rather the login/su process ID

Hi,

Can someone please advise how to get a login's process ID?

From the command line, echo $$ will show what I assume is my login's process ID. Is is possible to get this process ID from within a script?

To give a clear picture of what am wanting to achieve, I have a script that has to be run via su - sybase. The script searches for ps -ef | grep sybase | grep -v grep and then do a kill -9 of those processes, but doing so include that process that does the su - sybase as well so am wanting to be able to check what is the process ID of the su - sybase so I can exclude it from the the kill script.

FYI, the kill script has an exit at the end.

Any suggestion will be much appreciated. Thanks in advance.

Last edited by newbie_01; 09-20-2010 at 01:04 AM.. Reason: Change title
# 2  
Old 09-18-2010
echo $$ from the script. also you generally should avoid using kill -9 and only use this as a last resort. running kill -9 on database processes can cause corruption. if you really want to kill them then just kill it from root. no need for su.
# 3  
Old 09-18-2010
Quote:
Originally Posted by newbie_01
From the command line, echo $$ will show what I assume is my login's process ID.
$$ is the current shell process ID
Quote:
Is is possible to get this process ID from within a script?
Might be its parent process id which might be in the $PPID variable.
Quote:
The script searches for ps -ef | grep sybase | grep -v grep and then do a kill -9 of those processes
"kill -9" is almost always unwise, especially when done on sensitive processes like databases.
Quote:
but doing so include that process that does the su - sybase as well so am wanting to be able to check what is the process ID of the su - sybase so I can exclude it from the the kill script.
That's tortuous. Use pkill instead.
Quote:
FYI, the kill script has an exit at the end.
Which is probably useless as the script will exit at the end anyway ...
# 4  
Old 09-20-2010
Quote:
Originally Posted by frank_rizzo
echo $$ from the script. also you generally should avoid using kill -9 and only use this as a last resort. running kill -9 on database processes can cause corruption. if you really want to kill them then just kill it from root. no need for su.
Hi,

Oops, I think I placed the wrong title, what I meant is the process ID of the current login not the script as the script is ran using su - sybase. So am wanting to get the process ID of the su - sybase so I can exclude it.

The database does not run on this server, however I need to terminate the connections whenever this server has to fail over from one cluster to the other.

---------- Post updated at 11:02 PM ---------- Previous update was at 11:00 PM ----------

Quote:
Originally Posted by jlliagre
$$ is the current shell process IDMight be its parent process id which might be in the $PPID variable.
"kill -9" is almost always unwise, especially when done on sensitive processes like databases.
That's tortuous. Use pkill instead.
Which is probably useless as the script will exit at the end anyway ...
Hi,

Oops, I think I placed the wrong title, what I meant is the process ID of the current login not the script as the script is ran using su - sybase. So am wanting to get the process ID of the su - sybase so I can exclude it, is that the PPID as you mentioned?

The database does not run on this server, however I need to terminate the connections whenever this server has to fail over from one cluster to the other.
# 5  
Old 09-20-2010
you dont have to worry about the process id for the su process. this is running as root and the sybase user does not have permisson to kill it.
# 6  
Old 09-20-2010
Quote:
Originally Posted by newbie_01
So am wanting to get the process ID of the su - sybase so I can exclude it.
Don't confuse goals and ways to achieve them.
Do you want to retrieve specific process IDs or do you want to kill all the processes related to sybase ?
# 7  
Old 09-20-2010
Code:
Rather than:
ps -ef|grep "sybase"

Why not confine the list to those processes owned by user "sybase"?
ps -fusybase


Btw. I agree that "kill -9" is not good for database processes or process trees. Perhaps try "kill -15", wait a bit, then issue "kill -9" as a last resort.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

script to get child process for a process

!/bin/sh pid=$(ps -Aj | grep MSTRSvr | grep -v grep | awk '{print $1}') sid=$(ps -Aj | grep MSTRSvr | grep -v grep | awk '{print $3}') ps -s "$sid" I am not able to get the desired output it says process list error if i use watch ps -s "$sid" it considers only the first session id (5 Replies)
Discussion started by: schippada
5 Replies

2. Shell Programming and Scripting

script to monitor the process system when a process from user takes longer than 15 min run.

get email notification from from system when a process from XXXX user takes longer than 15 min run.Let me know the time estimation for the same. hi ,any one please tell me , how to write a script to get email notification from system when a process from as mentioned above a xxxx user takes... (1 Reply)
Discussion started by: kirankrishna3
1 Replies

3. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

4. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

5. Shell Programming and Scripting

script not killing process!

i am using script to connect remotly to server and run some commands , one of these commands is to kill some process but tried different ways with no hope sshpass -p 'pass' ssh -o StrictHostKeyChecking=no server kill -9 `pgrep procs` getting error message "kill: bad argument count" ... (2 Replies)
Discussion started by: mogabr
2 Replies

6. Shell Programming and Scripting

script script to kill a process

hello I need a shell script that takes the process name as an argument and kills the process. the process name is avilable in the long listing of the process.../usr/ucb/ps. this is urgent...pls. help (7 Replies)
Discussion started by: sreeniatbp
7 Replies

7. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies

8. Shell Programming and Scripting

Script - How to automatically start another process when the previous process ends?

Hi all, I'm doing automation task for my team and I just started to learn unix scripting so please shed some light on how to do this: 1) I have 2 sets of datafiles - datafile A and B. These datafiles must be loaded subsequently and cannot be loaded concurrently. 2) So I loaded datafile A... (10 Replies)
Discussion started by: luna_soleil
10 Replies

9. Shell Programming and Scripting

Process Monitoring Script

I need a script on Solaris 10 OS to monitor 3 seperate processes running. Each process has 3 of the same processes running a total of 9 processes and I need the ability to know if all of processes for each process is running and to email me if they aren't running. I'm new to Unix programming and... (3 Replies)
Discussion started by: soupbone38
3 Replies

10. Shell Programming and Scripting

killing process using a script

can I do ps -ef | grep <process_name> and kill the process is it exists? and send a mail to me that the process was found and killed Thanks much... KS (4 Replies)
Discussion started by: skotapal
4 Replies
Login or Register to Ask a Question