LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 12-14-2009, 12:15 AM   #1
girish_hilage
Member
 
Registered: Oct 2003
Posts: 78

Rep: Reputation: 15
using fork() in a pthread


Hi,

I have a requirement in which I am given a list of commands(e.g. ls, ps etc.) to be executed.
I want to execute these commands concurrently using popen() [which internally calls fork()].

My first idea was to use a pool of "pthreads" to do this. But, as I read from the URL's,

http://forum.soft32.com/linux/popen-...ict350819.html
http://helgafell.rhi.hi.is/libc/Thre...s%20and%20Fork

it does not seem to be safe to use fork() inside thread.

So, now I have decided to use a pool of "processes" to do this.
So, just wanted to confirm,
* if anybody has used fork() inside threads and what problems were faced if any?
* is it really unsafe to use fork() inside threads?
* if Yes, then, does c++ boost library guarantee any safety for calling fork() inside threads?

Regards,
Girish

Last edited by girish_hilage; 12-14-2009 at 02:46 AM.
 
Old 12-14-2009, 01:04 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
It sounds like your question is really:

Q: Is it safe to call "popen()" in a thread?

A: In general, yes. You shouldn't have any problems.

'Hope that helps .. PSM
 
  


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
fork vs thread/pthread powerplane Programming 17 08-11-2012 02:13 PM
Which is best for implementing SMTP servers in unix.. fork or pthread ? vskgopu Linux - Newbie 2 05-07-2006 09:40 PM
Which is best for implementing SMTP relay servers in unix.. fork or pthread ? vskgopu Linux - Networking 1 05-07-2006 07:47 AM
Which is best for implementing SMTP server in unix.. fork or pthread ? vskgopu Programming 1 05-06-2006 07:06 AM
Sockets, pthread, pipe, and fork -- a messaging server ggravarr Programming 3 06-28-2005 02:39 PM

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

All times are GMT -5. The time now is 12:04 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