Sorry, posts crossed and I now see that this is Informatica which is one of the most complicated packages known to man.
Providing so little detail about your environment and the real script is frustrating.
Quote:
test daemon that runs every 2 seconds.
What command do you type (or what crontab entry?) do you use to run this script? Exact commands please.
Quote:
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).
I do not see. There is no evidence posted which supports any part of this statement.
To run an external command, such as pmcmd, the shell must fork(), temporarily creating a copy of itself. This copy is a child whose parent is the original shell. Then the child execs, loading the new executable into its process.
Hi Allister, thanks for your reply. However upon further close investigation I noticed that the problem is not with pmcmd but with SQLPLUS command that I am calling within the script using backtick.
I broke down my script further and localized the problem to the oracle 'sqlplus' call I am making inside the script to run SQL queries. Sqlplus is Oracle's commandline tool for running database queries. Here is a short script I wrote to simulate the issue.
As you can see, the script does nothing much other than run in a loop. Within that loop it sleeps for 5 seconds and then calls a simple SQL DML operation through the Oracle Sqlplus utility with backticks. It also prints some messages to a temp file specifically for better understanding of the sequence of steps run.
Here is another script that runs in a loop, which I wrote just to track the processes running as the first script is runnning. It continuously looks for process testdbqueryforum.ksh usingg ps -ef output and prints it
Here is an extract of the output file written by the 1st and 2nd script above which gives an insight to the issue I want to understand about.
As you can see from the output pasted further below following is the sequence of events:
(1) I invoke the main script testdbqueryforum.ksh using the command sh /tmp/testdbqueryforum.ksh &(2) The main script sleeps for 5 seconds. At this time there is just one process called testdbqueryforum.ksh running with pid 9847
(3) After 5 seconds main script finishes sleeping and calls sqlplus command
(4) As soon as the sqlplus is invoked by the main script, we see 2 processes running with the name testdbqueryforum.ksh. One is pid 9847 and another is child process 10991. 10991 in turn calls another process sqlplus -s which I have not captured in this output but tracked offline
(5) Once the sqlplus process finishes running the SQL query, it returns the sql output to the main process which prints "Main finished calling sqlplus myvar= 14754"
(6) After this main script again goes to sleeping for 5 seconds and again you notice we are back to only one process with name testdbqueryforum.ksh running with pid 9847
Log output
----
----
I am perfectly fine with ps command and so that is not an issue. What I primarily interesting in knowing are the underlying system calls that the OS is making which is resulting in a child process with the same name as the parent process and then how come it is alive until the SQLPLUS command finishes executing and any other clarification on this behaviour.
thanks
Moderator's Comments:
Please view this code tag video for how to use code tags when posting code and data.
Hi Allister, thanks for your reply. However upon further close investigation I noticed that the problem is not with pmcmd but with SQLPLUS command that I am calling within the script using backtick.
From post #3
Quote:
Originally Posted by alister
Most likely, it's running a command in a subshell.
As Corona688 mentioned, what you're seeing is not a cause for concern.
Quote:
Originally Posted by waavman
I am perfectly fine with ps command and so that is not an issue. What I primarily interesting in knowing are the underlying system calls that the OS is making which is resulting in a child process with the same name as the parent process and then how come it is alive until the SQLPLUS command finishes executing and any other clarification on this behaviour.
Command substitution, `cmd ...` and $(cmd ...), works by creating a subshell to run commands. That subshell, which is initially a copy of its parent and shares the same name in the ps process list, will exist until its commands have completed. Why? Because that's how the shell works. It waits for synchronous (not in the background) commands to terminate before it itself exits.
How is the subshell created? UNIX process creation uses fork (or some optimized variant) to create a new process. This process begins life as an identical copy of its parent. For that process to become a different program, to load a new executable image, it needs to then call one of the exec family syscalls (usually execve).
On linux, the fork-variant used by the shell is probably clone.
If you're interested in monitoring system call activity, you might want to look into strace. It usually generates a lot of output. You can focus on the process creation system calls with -e trace=process. If you want the trace to follow the syscall activity of child processes (like subshells), use -f.
I rarely use Linux, so perhaps there are better monitoring tools these days. strace gets the job done for my simple needs.
Thanks for the explanation.
However to confirm that this behaviour is identical when I call any other program from within the script using backtick, I replaced the call to SQLPLUS with a call to a simple shell script that just sleeps for 2 secs and then prints hello. Surprisingly now, despite calling the shell script from within testdbqueryforum.ksh using backtick, I donot see two instances of the script (parent and child) when the 2nd process is spawned like how we noticed when invoking SQLPLUS with backticks. Do you know why there would be this inconsistency in behaviour.
Here is my modified testdbqueryforum.ksh script
This is what the script justsleepcommandremove.ksh contains
Here is the output from the log when running the 1st script using sh /tmp/testdbqueryforum.ksh &.
As you can see from the output below there are no two processes with the name /tmp/testdbqueryforum.ksh when the sleep script (instead of SQLPLUS) is invoked from within the main script using backticks
Your inputs on the reason for inconsistency in behaviour when invoking another shell script instead of sqlplus using backticks would be very much appreciated.
thanks
Last edited by methyl; 08-11-2012 at 08:26 PM..
Reason: Please use code tags ; Correct spelling mistakes for readabilty
Just because ps never saw it doesn't mean that it did not occur. Use strace to be sure. And for the definitive answer, look at your shell's source code to learn exactly how it implements command substitution.
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)
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)
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)
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)
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)
!/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)
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)
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)
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)
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)