Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I ran a script postData.sh, but when I do "ps -ef", I don't see the script in the list of programs running but I do see extra -bash processes running. How do I determine the pid so I can kill the script as it is in the background right now?

thanks, Dean

share|improve this question
    
-bash in ps -ef shows a login shells. Maybe another shell is opened? Your scripts maybe exited because in ps -ef you always can see a path to script like this: /bin/bash ./1.sh –  slimsuperhero Jun 26 '13 at 14:30

5 Answers 5

To get the PID of a process use:

pidof postData.sh

Alternative Way:

pgrep postData.sh
share|improve this answer
    
nope, that's not working –  Dean Hiller Jun 26 '13 at 15:15
    
than there is no process "postData.sh" running. to be sure you can check grep "postData.sh" /proc/*/cmdline - if this returns no match there definitly is no process running on your system that matches "postData.sh" –  Pascal Schmiel Jun 26 '13 at 15:18
    
well, they all seem to be running as -bash when I do ps -ef and when they finish my -bash count goes from 16 to 6 (I have 10 running). I see my startQa.sh in ps -ef but not these ones for some reason.....ahhh, I just realize the scripts I copied never had #!/bin/bash in them so that maybe screwed things up but I know they are running –  Dean Hiller Jun 26 '13 at 16:49
    
resolved...that was it...missing the #!/bin/bash is very very bad...posted the answer for why I could not see my process below. –  Dean Hiller Jun 26 '13 at 16:54

This might help you find it as it'll print the process ID, parent process ID, and extended command

ps -eo pid,ppid,start_time,command

and this will make a handy tree of the processes.

pstree -pu

If you find something that you might wish to pause, to assess if its the right processes, you can kill -STOP <pid>, and resume with a kill -CONT <pid>

share|improve this answer
    
hmmm, the script was not listed at all though one of the commands the script is running was posted but there are 10 of these scripts running with different names and the commands are all exactly the same –  Dean Hiller Jun 26 '13 at 15:14
    
@DeanHiller added to answer, maybe of use. –  Sirch Jun 26 '13 at 16:28
    
figured it out. scripts were missing the #!/bin/bash so they don't show up in anything except as -bash. –  Dean Hiller Jun 26 '13 at 16:54

OKAY, I resolved it. the scripts I copied off were missing the #!/bin/bash and for some reason when I run the script in ps -ef, it would just show up as -bash. Now that I added the #!/bin/bash, it properly shows up as

[root@sdi-prod-01 manytables]# ps -ef | grep postTemp
root     29165 28764  1 10:51 pts/12   00:00:00 /bin/bash ./postTemp.sh 1

grrrrrr, that was annoying and all my scripts are already running but I can't tell them apart because of this....live and learn I guess.

share|improve this answer

If it's the last process you backgrounded you can simply kill $!.

share|improve this answer

Using ps -x outputs the whole command.

share|improve this answer
1  
Your answer could do with expanding a little. It's unclear how the OP should use the -x or how this helps find the PID. –  Ladadadada Jun 26 '13 at 15:10
1  
Calling a ps -x, grepping it with the name of the script, then filtering every word but the first (PID), f. i. with a sed call, then that can be stored in a bash variable, f. i. THEPID, and then just calling kill $THEPID should. –  galegosimpatico Jun 26 '13 at 15:23
    
How is that an improvement over the ps -ef the OP said he's having trouble with? Also, it's better to edit your answer when improving it rather than adding the good bits in the comments below the answer. –  Ladadadada Jun 26 '13 at 15:46
    
Maybe for being noob, but I resist editing already commented comments because of trying not to steal sense from the at some extent child comments. Reading again am starting to think that the shell the OP is trying to find is actually no longer. –  galegosimpatico Jun 26 '13 at 15:54
1  
It's your answer that needs editing, not a comment. –  Michael Hampton Jun 26 '13 at 16:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.