Results 1 to 3 of 3

Thread: Will system call cause memory leak?

  1. #1
    Join Date
    Jul 2010
    Posts
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Will system call cause memory leak?

    Hi all,

    In my application I has to use many call to external command using the system("") call. My problem is even though this command is already finish, it still appear as a running job when I type the ps command on the console. For example:

    79 root /sbin/getty 38400 tty2
    82 root -sh
    83 root /sbin/syslogd -n -m 0
    84 root /sbin/klogd -n
    85 root /usr/bin/tail -f /var/log/messages
    105 root /AutoPrint -qws
    106 root [flush-179:0]
    107 root /AutoPrint -qws
    108 root /AutoPrint -qws
    109 root /AutoPrint -qws
    112 root [kjournald]
    122 root ps

    The PID from 107 to 109 came from my application (AutoPrint) after a system() command. If I run it long enough, there are many jobs with the same name (/AutoPrint -qws) come out when I type ps command. Is it a memory leak?

    Thank you very much

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: Will system call cause memory leak?

    system() is a C/C++ runtime API and/or an operating system API and of course should not leak memory or leave processes hanging, but what it does, depends on the call used and the operating system.

    You might want to use QProcess instead of system() for better control over the processes.

  3. #3
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Will system call cause memory leak?

    If the system call returns, the command should be finished and the shell it launched in closed, unless the command was launched in the background. In this case, the call would likely never turn and your program would hang.

    Also, ps seems to be reporting that instances of YOUR program are persisting rather than the commands launched by it, assuming your application is named AutoPrint. If so, then your program isn't exiting properly and the problem has nothing to do with system calls.

Similar Threads

  1. Replies: 8
    Last Post: 21st March 2011, 12:40
  2. memory leak - where?
    By Tomasz in forum Newbie
    Replies: 36
    Last Post: 5th September 2010, 23:47
  3. Qt dll + memory leak
    By Fastman in forum Qt Programming
    Replies: 3
    Last Post: 2nd August 2009, 13:28
  4. Memory leak of Qt?
    By Sheng in forum Qt Programming
    Replies: 1
    Last Post: 1st April 2009, 23:32
  5. Memory leak?
    By Enygma in forum Qt Programming
    Replies: 10
    Last Post: 4th September 2007, 16:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.