LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-16-2010, 07:27 PM   #1
raghu2383
LQ Newbie
 
Registered: Jun 2008
Posts: 20

Rep: Reputation: 0
C code fails on repeatedly opening /proc


Hello,

I am trying to run my code repeatedly in a loop about 50 times for timing measurement. I have C code running on ubuntu 8 on a single processor, Intel x86. My code is something like this

Code:
for (loop =0;loop<=50;loop++)
{
// other operations

pDir = opendir("/proc");
while (pDir == NULL)
{
usleep(10);
pDir = opendir("/proc");
}
// some computations

closedir(pDir);

// other operations
} // end of loop
After about 28-29 times the loop stops executing. I initially had a return -1 if I got pDir == NULL. That caused my program to exit, and I dont want that. Any clues on why this happens, and how I can circumvent this?

Thanks for looking into this.
 
Old 01-16-2010, 07:48 PM   #2
raghu2383
LQ Newbie
 
Registered: Jun 2008
Posts: 20

Original Poster
Rep: Reputation: 0
Sorry about that. I found I had an unclosed file handle in my loop which was causing a crash. Now even 1000 times does not cause an exit.
 
  


Reply

Tags
code, directory, linux, opening


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
login repeatedly fails dla-nor Fedora 5 10-18-2008 06:12 AM
Installation of Ubuntu 8.04 fails repeatedly due to partitioning problems NGKEIB Linux - Newbie 7 07-13-2008 05:39 AM
LILO install fails repeatedly HippoGorgeous Linux - Newbie 1 07-01-2004 02:33 PM
/proc/acpi/... slow opening (tm) Linux - General 1 04-21-2004 06:43 AM
Mandrake 9.1 X boot manager fails repeatedly brainunused Mandriva 3 03-29-2004 12:00 PM


All times are GMT -5. The time now is 07:18 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration