Sponsored Content
Top Forums UNIX for Advanced & Expert Users Unix script seems to be momentarily creating child process for unknown reason Post 302682191 by waavman on Sunday 5th of August 2012 06:33:11 PM
Old 08-05-2012
Unix script seems to be momentarily creating child process for unknown reason

Hi,
I have a unix script that basically has a while loop inside which it checks Oracle database for certain records. If it finds the records, it does some processing and then goes back to the while loop. If it doesnot find any matching records, then it sleeps for 30 seconds and then goes back to the while loop to again check for existence of a new records.
We are supposed to have only one instance of this script running. The script is kicked off at the beginning of the week with the command sh scriptname.ksh &
It doesnot need to be started again until after server reboot the following week.
To ensure that not more than one instance of the script runs, we have a monitoring program that alerts us whenever multiple instances of the script are running due to either multiple users mistakenly starting a new instance of the script or some other reaosn. After seeing occassional alerts from this monitoring system that multiple instances of this script were running, I decided to see why the monitoring system was alerting us on multiple instances. So I wrote a temporary script that runs in an infinite loop and runs the command ps -ef|grep scriptname |grep -v grep every 2 secs. After analyzing the output of this test daemon that I wrote, I found that once in a while (eveyr 15 or 20 minutes), ps -ef returns two instances of the script.
(1) One instance has parent pid equal to 1
(2) The 2nd instance of this script has pid equal to the parent pid of the 1st process
Within a couple of seconds after that, my daemon shows that the 2nd instance has died and again there is only one instance.
So why does this 2nd instance get triggered by the parent process momentarily thereby misleading our monitoring system to believe that there are multiple instances of the script running.
Here is an output of the ps -ef run by my test daemon that runs every 2 seconds. As you can see from the output below, at 5:44:04 pm Aug 5, you can see 2 instances of the script running (in bold). 1st instance is parent script which has pid 12369. 2nd instance is Child script which has pid 5713 and whose parent pid is the pid of the parent script 12369. I have no idea how the child script with pid 5713 got triggered . myscriptname.ksh doesnot call itself. As mentioned before, it just runs in a while loop waiting for database changes and does some processing if there are database changes but it never calls itself anywhere. AS you can see below, within 2 secs at 5:44:06 PM, the child instance of the script with pid 5713 suddenly dies and we are back to just 1 instance again (pid 12369). This happens occassionally (maybe once every 15 minutes) but I donot know why. If you can explain the reason for this behavior of the parent process momentarily invoking a child process which calls the same script as the parent script and which dies within 2 secs, your help would be highly appreciated.
The script is running on SUSE Linux v10.3

Code:
Sun Aug  5 17:44:00 EDT 2012
ownerid     12359     1  0 04:10 ?        00:00:08 sh myscriptname.ksh
Sun Aug  5 17:44:02 EDT 2012
ownerid     12359     1  0 04:10 ?        00:00:08 sh myscriptname.ksh
Sun Aug  5 17:44:04 EDT 2012
ownerid      5713 12359  0 17:44 ?        00:00:00 sh myscriptname.ksh
ownerid     12359     1  0 04:10 ?        00:00:08 sh myscriptname.ksh
Sun Aug  5 17:44:06 EDT 2012
ownerid     12359     1  0 04:10 ?        00:00:08 sh myscriptname.ksh
Sun Aug  5 17:44:08 EDT 2012
ownerid     12359     1  0 04:10 ?        00:00:08 sh myscriptname.ksh

thanks

Moderator's Comments:
Mod Comment edit by bakunin: Please use code tags next time for your code and data.

Last edited by bakunin; 08-07-2012 at 04:54 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script to kill all child process for a given PID

Is there any build in command in unix to kill all the child process for a given process ID ? If any one has script or command, please let me know. Thanks Sanjay (4 Replies)
Discussion started by: sanjay92
4 Replies

2. Programming

creating child process

i want to create 3 child processes from the same parent using folk. I know how to use folk but my child processes did not come from the same parent. Any suggestion what i did wrong ? (12 Replies)
Discussion started by: Confuse
12 Replies

3. UNIX for Dummies Questions & Answers

UNIX System Call for creating process

Hell Sir, This is chanikya Is there any System call which behaves just like fork but i dont want to return back two times to the calling func. In the following ex iam creating a child process in the called func but the ex prints two times IN MAIN. ex :- calling() { fork(); } ... (2 Replies)
Discussion started by: chanikya
2 Replies

4. Shell Programming and Scripting

Dropping Records for unknown reason in awk script

Hi, I have written the following it is pretty sloppy but I don't see any reason why I should be losing 54 records from a 3.5 million line file after using it. What I am doing: I have a 3.5 million record file with about 80,000 records need a correction. They are missing the last data from... (8 Replies)
Discussion started by: mkastin
8 Replies

5. 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

6. Shell Programming and Scripting

creating an automation process in unix .

hi i need shell script in ksh for the automation process in informtica. The automation process is like this . i have a folder in unix . when this folder gets updated (like if a file or files is/are added to the folder) an event in informatica is triggered and after the process is done in... (2 Replies)
Discussion started by: kumar8887
2 Replies

7. Shell Programming and Scripting

forking a child process and kill its parent to show that child process has init() as its parent

Hi everyone i am very new to linux , working on bash shell. I am trying to solve the given problem 1. Create a process and then create children using fork 2. Check the Status of the application for successful running. 3. Kill all the process(threads) except parent and first child... (2 Replies)
Discussion started by: vizz_k
2 Replies

8. Shell Programming and Scripting

Kill all child process of a script

Hi guys i have a problem with a script... this script creates differents GUI with YAD... well i want that when i press the "Cancel" button on this graphical interface all the child process and even the same script should be killed #!/bin/bash function gui_start { local choice="" ... (4 Replies)
Discussion started by: maaaaarco
4 Replies

9. Shell Programming and Scripting

SSH is failing due to unknown reason

Hi, I have setup keys between user1@server1 and user2@server2 however, the ssh is failing. server1 is Linux 3.10.0-514.6.2.el7.x86_64 #1 SMP whereas server2 is 5.10 Generic_150400-40 sun4v sparc sun4v I have checked port 22 to be open and keys to be correct. I also find the permissions... (3 Replies)
Discussion started by: mohtashims
3 Replies

10. Shell Programming and Scripting

Url check creating child process and generating false alerts

Hi All Below code is working as expected but creating too many child processes when the url is not up and every minute that process is sending false email alerts any help with the logic not to generate child process and not to send duplicate alerts app="https://url" appresult=$(wget... (2 Replies)
Discussion started by: srilinux09
2 Replies
All times are GMT -4. The time now is 03:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy