Multiple process found when executed from script


 
Thread Tools Search this Thread
Operating Systems Linux Multiple process found when executed from script
# 1  
Old 05-05-2016
Multiple process found when executed from script

Hi All,

I came across a weird scenario which i couldnt explain why.
As part of script which is run as /bin/sh shebang, we are trying to check if there is any process that runs with the same name ignoring the current process and kill it.
But for some reason, there are 2 process returned as part of echo and kill command for same process name. But if we do just ps -edf we just get one.

Please find belwo the commands

Code:
 
 echo ` ps -edf | grep process_name | grep -v pattern | grep \? | grep -v grep `
  
 kill -9 `ps -edf | grep process_name | grep -v  pattern | grep \? | grep -v grep | nawk '{print $2}' | sed "s/$$//g"`

Both the above command returns 2 process(the output of command within ``), one is the current process which is created when the script is executed and the second one comes as a child of the first process but with same command. The second process gets killed forcefully and its causing a failure trigger for my job which uses that script.

If i use below command on the same script, i just get the current process.
Code:
ps -edf | grep process_name | grep -v pattern | grep \? | grep -v grep

Any inputs is highly appreciated

Regards,
Pradeep
# 2  
Old 05-05-2016
Try the pkill command pgrep also helps

Say the process is running the foo command or any other command or script
Code:
pgrep foo   # print the process pid running foo
pkill foo # kill the foo process.

Obviously you need the privilege to kill the process == you must be root the user
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Open Source

Help with writing Shell Script to automate process using multiple commands

Hello! Need help to write a Linux script that can be run from windows using command/Cygwin/any other way. I am new to scripting, actually i am trying to automate server health check like free disk space, memory along with few services status, if any services is not running then start services ,... (7 Replies)
Discussion started by: Sayed Ibrahim
7 Replies

2. Shell Programming and Scripting

Shell script replied multiple process for file has successfully created

Hi All, I have written the following code do FILE_NO=$(echo $LINE|awk -F"|" '{print $1}'|tr "'" '+'|sed 's/\(.*\)\(++\)\(.*\)\(++\)/\3/') INST_NO=$(echo $LINE|awk -F"|" '{print $2}'|tr "'" '+'|sed 's/\(.*\)\(++\)\(.*\)\(++\)/\3/') if ] then ... (3 Replies)
Discussion started by: yogendra.barode
3 Replies

3. Shell Programming and Scripting

Multiple shell scripts executed in one script

Hi every one, i am new to shell script. my people given a task to write a shell script that should execute number of shell scripts in that. in that, if any shell script is failed to execute, we have to run the main script again, but the script should start execute from the failed script only.. it... (6 Replies)
Discussion started by: Madhu Siddula
6 Replies

4. Shell Programming and Scripting

Multiple shell scripts executed in one script

Hi every one, i am new to shell script. my people given a task to write a shell script that should execute number of shell scripts in that. in that, if any shell script is failed to execute, we have to run the main script again, but the script should start execute from the failed script only.. it... (1 Reply)
Discussion started by: Madhu Siddula
1 Replies

5. UNIX for Dummies Questions & Answers

Writing a loop to process multiple input files by a shell script

I have multiple input files that I want to manipulate using a shell script. The files are called 250.1 through 250.1000 but I only want the script to manipulate 250.300 through 250.1000. Before I was using the following script to manipulate the text files: for i in 250.*; do || awk... (4 Replies)
Discussion started by: evelibertine
4 Replies

6. AIX

Script not getting executed via cron but executes when executed manually.

Hi Script not getting executed via cron but executes successfully when executed manually. Please assist cbspsap01(appuser) /app/scripts > cat restart.sh #!/bin/ksh cd /app/bin date >>logfile.out echo "Restart has been started....." >>logfile.out date >>logfile.out initfnsw -y restart... (3 Replies)
Discussion started by: samsungsamsung
3 Replies

7. UNIX for Advanced & Expert Users

commands not working if the executed from forked process

Hi, I have an application where if it runs indivisually could able to execute commands (like system("ls")) and could able to execute tcl script. Same application if started from health monitor process (From health monitor process my application will be forked), it could not execute the... (1 Reply)
Discussion started by: chandrutiptur
1 Replies

8. UNIX for Dummies Questions & Answers

multiple commands to be executed at the same time

how to execute more than one command at the same time in unix .. (4 Replies)
Discussion started by: hemaa
4 Replies

9. Shell Programming and Scripting

Shell stop process after found value in file

hi guys can somebody help me here... i've a file that contains total of ip that connects to my server and their ip like this : 80 80 xxx.xxx.xx.xxx 75 75 xxx.xxx.xx.xxx 73 73 xxx.xxx.xx.xxx where first columns and second were the total connections... ... (0 Replies)
Discussion started by: kriezo
0 Replies

10. UNIX for Dummies Questions & Answers

Crons executed multiple times.

For some reason my crons are being executed twice. Any suggestion?? I'm currently on 5.8 (2 Replies)
Discussion started by: shorty
2 Replies
Login or Register to Ask a Question