Apparantly, Iam using a sleep command to make sure that the files that are used below are generated . Without sleep the code is proceeding without My_List.txt being created. My_List.txt gets created by the system shell scipt command.

Is there any alternative approach than sleep One example would be run a loop to check the process matching Init.sh , and if process is running i would not proceed If the process is run , i'll proceed with the further code.

How to check for a process in a loop and proceed with futher code only if process is completed.

Re: [Tejas] Check whether the process exists in perl and proceed with the further code if the process id is not found
[In reply to]

Can't Post

The system() function is a blocking function and won't return (execute the sleep call) until it receives an exit code from the process it executes. If you run your command in the background (i.e., append & to your command), system() will return immediately without waiting for the child process to complete.

You are not running your shell script the the background, but what I suspect is going on is that sh is returning its exit code rather than your shell scripts exit code and is not waiting for your script to complete before returning that code.

Start by removing sh from the command since it's not needed because the system function already uses sh to execute the command and remove the sleep call. If that doesn't resolve the problem, then we will look at the other options.

We'd need to run some debug tests to verify the execution flow but that flow is likely to be this:

System function forks a sh subshell -> your command forks another sh subshell to execute your shell script. Which exit code do you think is being passed back to perl? The one from your shell script, the one from your subshell, or the one from the subshell created by system()?

Re: [Tejas] Check whether the process exists in perl and proceed with the further code if the process id is not found
[In reply to]

Can't Post

Quote

By not working i meant, system command is not blocking or some times it is blocking .

No, that's not how it works. The system function will always block until it receives the exit code from the child process.

Does the shell script run the C++ executable in the foreground or background? If it runs it in the background, then it's very likely that the shell script is returning/exiting prior to that background process completing. That would explain the symptoms you're seeing.