LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-05-2013, 05:57 PM   #1
dreamalive
LQ Newbie
 
Registered: Jun 2013
Posts: 1

Rep: Reputation: Disabled
Calling popen from a daemon.


I have a process where I call daemon(int nochdir, int noclose), specifying true for nochdir and false for noclose. I then wish to call popen to have a command do work for me and then send its stdout back to my process. This works fine if daemon() is not called first.

My understanding was that daemon() will redirect stdout, stdin and stderr to /dev/null but that popen should still be able to do its thing and redirect the stdout of the command I specify in the popen call to the pipe file descriptor returned from the popen call. Why doesn't this still work even if my process is running as a daemon?
 
Old 06-10-2013, 12:59 AM   #2
Ygrex
Member
 
Registered: Nov 2004
Location: Russia (St.Petersburg)
Distribution: Debian
Posts: 666

Rep: Reputation: 68
it does work fine: http://codepad.org/VXbJUMQV

Code:
$ rm -f /tmp/result ; ./a.out ; sleep .5 ; cat /tmp/result 
result: 0
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
popen crashes shabbirlimdiwala Programming 6 10-16-2012 06:04 AM
[SOLVED] popen in c ankitm Programming 4 12-07-2011 02:24 AM
calling system command in daemon csfalcon Programming 2 05-13-2005 12:17 PM
odd recursion: calling "by hand" vs calling by cronscript... prx Programming 4 02-12-2005 05:59 PM
C Popen gold5angel Programming 2 04-17-2004 08:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:16 AM.

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