Why the disk space keep on decreasing,is that due to use popen()?

C

CFAN

Why the disk space keep on decreasing,is that due to use popen()?
I have wrote a monitor program to ensure my program on working by
using popen to
use 'ps' command, but the disk space keep on decreasing.

And when the disk shrink to near 40K , it seems stop to decrease
anymore.

So Is the popen implementation needs write disk other than using meory
instead?
got wired.
And also , can their be a way to only access the memory for my
program's purpose?

Following is the code :

#define PS_COMMAND "ps -ef | awk '{print $2 , $8;}'| grep %s |grep -v
grep"
main()
{
while (_GetProcessId("programA",&already_start))
{
//do something ... and sleep a minute.

}

}

int _GetProcessId(char *program_name,int* already_start)
{

FILE *fd;
char command[255];
char str[255];
sprintf(command,PS_COMMAND,program_name);
if((fd = popen(command, "r")) == NULL) {
printf("call popen failed ");
return APR_EINIT;
} else {
while(fgets(str, 255, fd) != NULL) {
//printf("%s ",str);
*already_start=atoi(str);
pclose( fd ) ;
return APR_SUCCESS;
}
}
pclose( fd ) ;
return APR_EGENERAL;
}
 
W

Walter Roberson

Why the disk space keep on decreasing,is that due to use popen()?

We don't know. popen() is not part of the C standard. You will need
to ask the question in a forum that deals with the peculiarities
of your operating system.
 
L

liking C lang.Chinese

We don't know. popen() is not part of the C standard. You will need
to ask the question in a forum that deals with the peculiarities
of your operating system.

I think so.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top