Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

3 lines of code that crashes after a while

yanosyanos Member Posts: 2
i've set up a timer that execute those 3 lines of code every time it expire (10 seconds intervals). When i let the code run for about 4-5 hour, it crashes, but im clueless has to why it does so. cmdOutput is a FILE*

cmdOutput = popen("ftpwho -v", "r");
char buff[2];
int a = fread(buff, sizeof(char), 1, cmdOutput);

There is nothing else in my code. Just that and the timer and if i comment out the lines above and let only the timer execute, it run fine for days.

could someone point some clues?

Comments

  • FlatlineFlatline Member Posts: 1
    : i've set up a timer that execute those 3 lines of code every time it expire (10 seconds intervals). When i let the code run for about 4-5 hour, it crashes, but im clueless has to why it does so. cmdOutput is a FILE*
    :
    : cmdOutput = popen("ftpwho -v", "r");
    : char buff[2];
    : int a = fread(buff, sizeof(char), 1, cmdOutput);
    :
    : There is nothing else in my code. Just that and the timer and if i comment out the lines above and let only the timer execute, it run fine for days.
    :
    : could someone point some clues?
    :

    A process is only allowed to have so many open file descriptors.
    Since you're not calling pclose() for each time you're calling
    popen(), it's only a matter of time before you hit the limit.

    Flatline
  • Justin BibJustin Bib USAMember Posts: 0

    { http://forcoder.org } free ebooks and video tutorials about { Objective-C Go Perl C# PL/SQL Visual Basic PHP Ruby JavaScript Swift C++ Java Scratch R Delphi MATLAB Python Assembly Visual Basic .NET C SAS Ada Logo VBScript Fortran Crystal Scheme ABAP Alice Rust Clojure Lisp ML Julia Dart Hack LabVIEW F# Transact-SQL Kotlin Apex FoxPro Lua Awk Scala Prolog Erlang COBOL D Bash } _______

Sign In or Register to comment.