System call failed with 127 .. after 500 times when called in loop


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users System call failed with 127 .. after 500 times when called in loop
# 8  
Old 01-13-2012
There's nothing wrong with your program. I suspect something else on your system is causing occasional low memory conditions which make your program occasionally fail to create processes.
# 9  
Old 01-13-2012
Would be nice to know what Operating System and hardware we have here.
For all we know it might be a 1980's system.

It is a well known fact that the unix "ps" command will fail occasionally if the kernel gets busy. I have monitoring scripts which deliberately ignore abnormal results from "ps" unless they persist.
However bombarding the kernel with a program in a tight loop is not a good idea. An earlier poster suggested introducing a "sleep" in the loop. Very wise.

You refer to "too many forks". Is that an error message in a system log? If so, please post the error message verbatim.
# 10  
Old 01-20-2012
Tools

Hello all in group,

I have Fixed Smilie the actual issue that was causing a pain to the poor 'system() api' call Smilie that i had been doubting on for the past few weeks. The problem wasn't with unavailable memory (that i earlier suspected Smilie due to uncleaned child processes) etc etc. this magic number of failure "after around 500" gave me clues that either "uncleaned child processes" or its "other limits reached". If it was the first one, then even if the command was executed directly on the shell console, it would fail, but in my case it din't happen that way. So, i concentrated on the second case. Google-d 10's of links about resource limits and learned some facts about NR_TASKS, file descriptor max etc and found numbers like 512, 1024 etc.

The actual problem was like this.

after system("script.sh > file.txt") had been called, there were two other functions that were later executed. In those functions, there was one operation like this...
DIR* dir = opendir("/data/cores");

what has actually happened is, my kernel allowed only 1024 open file descriptors per process (ulimit -n) as default. once the testing started, each loop will open 2 descriptors, but didn't close them. As a result, after approx 500 times, approx of 1024 descriptors was still open (known to the kernel) by the process itself, and after that when system call system(..) API tried to open file.txt using the 'cat' ">" file.txt, it did not get a free descriptor from the kernel. and hence the execl inside the system(.) call API failed, returning 127 error code.

How did i find?
One possible way is to re-compile kernel enabling all debug logs around the glibc areas.
i dint go by the above. I tried to open a file next to system() call api directly using 'open' system call, and that returned NULL. What if you use 'perror" after that failure. The whole thing is there. It coveyed the whole information of what was going wrong. Smilie

also later i learnt that in /proc/pid/fd if you see will list all file descriptors that are in use. Ideally there will be 3 or 4 default. in my case, there were 1024 :P

GAME OVER Smilie

Thanks Smilie
# 11  
Old 01-20-2012
Glad you figured it out.

Quote:
Originally Posted by binnyjeshan
after system("script.sh > file.txt") had been called, there were two other functions that were later executed.
Had you posted the complete code, you could have gotten the problem figured out much sooner Smilie
# 12  
Old 01-21-2012
Compiling kernel is probably overkill. You could've used strace (or truss).
# 13  
Old 01-21-2012
We'll probably never know which Operating System this was or the proceise symptoms of the fault.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk call in bash function called with arugments not working, something lost in translation?

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)
Discussion started by: LMHmedchem
5 Replies

2. Shell Programming and Scripting

Bash script from makefile - it is called each time i call make

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)
Discussion started by: Pufo
0 Replies

3. Shell Programming and Scripting

Reset while loop to loop same file multiple times

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)
Discussion started by: tmalik79
4 Replies

4. UNIX for Dummies Questions & Answers

shell program- how many times a function is called

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)
Discussion started by: oana06
0 Replies

5. UNIX Desktop Questions & Answers

for loop (001 to 500)

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)
Discussion started by: boaz733
2 Replies

6. Programming

parent called more times - fork - C language

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)
Discussion started by: wakatana
7 Replies

7. Shell Programming and Scripting

To call a Oracle sql file 1000 times

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)
Discussion started by: mac4rfree
4 Replies

8. Shell Programming and Scripting

call a passwd file to a script multiple times

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)
Discussion started by: raghu.iv85
1 Replies

9. BSD

Deny logon for x hours if login failed x times

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)
Discussion started by: brightstorm
2 Replies

10. UNIX for Dummies Questions & Answers

Session request failed (Called name not present)

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)
Discussion started by: Spetnik
4 Replies
Login or Register to Ask a Question