System call failed with 127 .. after 500 times when called in loop
Hi Experts,
I have a code like this.
=====
Content of the test.sh is.
Problem is that, after this code is looped for 500+ times, the error happens
Problem generating static log: shell script returned 127
In the meantime when the error is happening, if you execure this manually on the shell, i.e. test.pl > log.txt .. it works fine..
ONLY WHEN IT HAPPENS THROUGH SYSTEM CALL, it fails
after failing for 30 times, it resumes again successfully.
I have tried to replace system() with popen(), but that also gives same behavior.
What would be the reason? Is it that the fork() ed child processes by these two functions (internally) did not free the resources?
did /bin/sh fail to launch? Did the system have no memory to fork?(if so, why did it resume after 30 continuous failures?
I am looking for your suggestions and comments.
Thanks for the help and your time,
Binny Jeshan,
Senior Software Designer,
Aricent.
Last edited by binnyjeshan; 01-20-2012 at 03:04 AM..
Reason: typing error rectified; please use code tags
What is the while condition here? Is it while(true)?
If so, the problem may be the delay caused by execution of the script.
You call the script 500 times, but it cannot catch up; I would think the commands are being fork()-ed, which takes some time, and resources need to be allocated. The forked processes don't have the time to resolve, and more and more forks are requested. Then, as the system cannot do any more, execution fails. After some 30 loops, the system catches up executing the script and resources are freed to continue the mad race.
There is a limit to how many forks can your program do at one time. This may be the culprit.
This is just my vague idea of what's happening. I am looking forward to read some more accurate answers
I don't think the number of processes would limit it. system() waits for the process it creates to complete, and nothing inside that script ought to be leaving anything behind.
That doesn't mean fork isn't failing -- I just can't imagine why it would be.
Unless you actually want it to buffer, everything you print with printf() should end with \n, not begin with it, since an \n on the end will cause it to print immediately and not buffer.
You might try perror("error code was ");before you print the exit status, to see if errno contains anything illuminating after system() fails.
---------- Post updated at 10:58 AM ---------- Previous update was at 10:54 AM ----------
A process dying with code 127 usually means it was killed by a signal of some sort. Something from the outside may be killing them, or they may be exceeding some sort of resource limit and being killed.
The question is only WHY it fails after say 500 times.. During this time i found some references regarding fork: resource unavailable, but i dont think these will solve the problem that i face.
@ MIRNI: You could be right..But for every one cycle, the system call after it returns back, it ensures that it checks the exit status of the child, and frees up the resources it takes.
In the man page i see this statement like this.. As mentioned, system() ignores SIGINT and SIGQUIT. This may make programs that call it from a loop
uninterruptible, unless they take care themselves to check the exit status of the child. E.g.
But i feel the above statement should now be same as popen. SO i think the issue should be with fork since both these utilities have it as common.
Supposedly as told in man page (and even i call it in loop), if the exit status was not fine, and after continuous calls it failed, if we find it in between, what action to take? instead of the "break" above, should i manually set the return status and clean something? I am not sure.
Please share your ideas now.
And i dont think the "\n"s added here impacts the functionality of the system (). Tested it.
For the first 500 times, its fine.. after that its not working. unless u reboot and try again to enter the condition.
The number is not exactly 500.. .it sometimes is 487, 510 .. 505 etc..
Yes i also suspect that its resource unavailable... But Why? If system call cleaned up all child process resources that it internally created to do the shell command, then when it returns back, we expect no memory leaks or 'defunct'-ed processes.
Hello,
I have this awk code in a bash script to perform a find and replace task. This finds one unique line in a file and substitutes the found line with a replacement.
#! /bin/bash
# value determined elsewhere
total_outputs_p1=100
# file being modified... (5 Replies)
I've created a tag in the makefile:
mytag: $(shell ${PWD}/script.sh)
When i do: make clean - the script is executed
When i perform make or make mytag the script is again executed with the output:
make: Nothing to be done for mytag
What i want ?
I want script.sh to be executed only... (0 Replies)
Hi,
I want to read file multiple times. Right now i am using while loop but that is not working.
ex.
While read line
do
while read line2
do
echo stmt1
#processing some data based on data.,
done < file2.txt
done < file1.txt # This will have 10... (4 Replies)
We have a program source C and is required to indicate how many times each function is called from the C program. also print the line number where there is a call.
I've tried something like this:
#!/bin/sh
for i in $*;do
if !
then
echo $i is not a C file.
else echo $i... (0 Replies)
hey,
how do i create a for loop that runs for i from 001 to 500 ?
i need that the zero prefix will remain so when i print "i" it will
look like so:
001
002
.
.
008
009
.
.
058
059
.
.
500
please advise. (2 Replies)
Hi gurus can you explain following lines of code ?
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(void)
{
pid_t pid;
int rv;
switch(pid = fork()) {
case -1:
... (7 Replies)
Hi Guys,
Even though, i have called db2 sql file earlier, this is my first time to call a oracle sql file.
I need to make a database(oracle) connection and then call the sql file in a loop.
Can you please help me out.
Thanks for your help and time.
Regards,
Magesh (4 Replies)
Hello everybody,
I have a requirement in my script..
When i'am executing a script, it'll ask a passwd of some service account.. I need to pass it to the script through a zipped file when it asks for it.
The script can be executed by more people many number times. So for securty purpose, it... (1 Reply)
Hello,
I have a small inquiry.
Sometimes, my good friend, Charlie Root, sends me security notifications that a possible breakin attempt has occured. It looks like this:
Oct 29 06:58:17 cigva sshd: reverse mapping checking getaddrinfo for 180.144.164.220.broad.sm.yn.dynamic.163data.com.cn ... (2 Replies)
I have the following shell script to map a drive to a windows machine:
echo Enter password:
stty -echo
read passwd
stty echo
mount -t smbfs -ousername=myusername,password=$passwd //192.168.2.5/sharename /mnt/mountname
It works fine and the share mounts, but for some reason I get this... (4 Replies)