LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-11-2011, 04:04 AM   #1
shankar.489
Member
 
Registered: Jan 2011
Posts: 53

Rep: Reputation: 0
Question Help regarding popen() and pclose()


hi folks,

iam a newbie to linux environment iam using popen() to run script(s) in thread(s)

all i need is my scripts should execute in parallel without starving for cpu and log the results(of scripts) in to log.

here i cannt use pclose because it will close process as well as pipe opened by popen (), i need to use this pipe for logging later.

so i did following code change in my code to acheive popen(),pclose() functionality.

is there any pitfaults/leaks with my code if so please let me know.

int main ()
{
FILE *Fp = NULL;
char buf[128]={0};
int pid;
int status;

Fp = popen("./myscript.sh", "r");
fgets(buf,128,Fp);

pid=atoi(buf);

if ( waitpid((pid_t)pid,&status,0) <0)
{
printf("wait failed:\n");
}

fclose(Fp);

return 0;
}

it is working fine but i need to know above code effects in complete process(i mean run time errors).

thx in adv

~shankar
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
python 2.6.4 os.popen os.system jabfinger Programming 2 02-26-2010 10:22 AM
Help using popen and execl cdog Linux - Software 3 02-28-2007 06:44 PM
popen for windows csfalcon Programming 6 11-30-2005 08:21 AM
popen output not appear dimsh Programming 4 10-22-2005 02:56 AM
C Popen gold5angel Programming 2 04-17-2004 07:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration