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;
}
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;
}