linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Uğur ATA" <ataugur@gmail.com>
To: linux-c-programming@vger.kernel.org
Subject: Ever Increasing Stack Size and not reclaimed
Date: Thu, 28 Jan 2010 11:56:45 +0200	[thread overview]
Message-ID: <8eec89ee1001280156k5fa5b999q78171193399f2b9f@mail.gmail.com> (raw)

Hi,

I have a problem with a deamon process that I have written. It is
listening some text commands on a local socket and does some
background job. I am using the same executable to send commands to the
deamon process. What I observe is that it crashes after some time and
it is only when RSS size reaches 65500K.

I suspected of a heap problem at first and i have used valgrind to
track memory issues. It helped me to find some minor memory leaks but
it didn't affect much. Later I have written a logging method to log
current memory usage when called as below:

void getMemoryUsage(char *position) {
    char result[BUFFER_SIZE + 1];
    char* command =
    "ps -eaf | grep BSM | grep -v grep | awk '{print $2}' | xargs ps
-ly -p | tail -1";

    FILE* ptr;

    pthread_mutex_lock(&mutex_mem);
    if ((ptr = popen(command, "r")) != NULL) {
        fgets (result, BUFFER_SIZE, ptr);
        int len = strlen(result);
        result[len - 1] = '\0';
        log_debug("|%s||%s|\n", position, result);
    }
    pthread_mutex_unlock(&mutex_mem);

    pclose(ptr);
}

Sample output for this is:

[2010-01-28 12:31:19.162] |::loop1::||S     0 13967     1  0  80   0
944  5170 pipe_w pts/1    00:00:00 limit|


What i recoginezed is that the RSS value increases in each different
method call by 4K in the first call only.

For example in the following command RSS increases by 4K but only in
the first time. When it is called again RSS does not change:
    char* end_of_command = strchr(message, KEY_SOCKET_SEPERATOR);

This is almost the same for every other method type. So I thought that
it is because of the stack increase in each call or something. The
problem is that RSS usage never drops when a method returns and keeps
increasing in each call thus reaching near 65M and program crashes.

Does anybody have a clue on what might be causing that weird behaviour?

Thanks in advance.

                 reply	other threads:[~2010-01-28  9:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8eec89ee1001280156k5fa5b999q78171193399f2b9f@mail.gmail.com \
    --to=ataugur@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).