* Replacing fork/exec with spawn question
@ 2012-11-25 16:53 Devin Nate
2012-11-25 17:14 ` LMH
2012-11-25 19:51 ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
0 siblings, 2 replies; 5+ messages in thread
From: Devin Nate @ 2012-11-25 16:53 UTC (permalink / raw)
To: cygwin
Hi folks,
I'm looking for some documentation about the cygwin spawn use, or a recommendation of a package that has had fork/exec replaced by spawn that I can review to see how someone else did it. Preferably less intimidating than gcc, and which uses pipes for IPC between parent and child.
In particular, the code I'm looking to patch does a typical fork/exec and uses 2 pipes to communicate bi-directionally parent to child. The pipes are throwing me off as to if cygwin spawn is usable.
I've been through the spawn.cc code, and see spawn_guts has a concept of __stdin and __stdout, but I don't see those params used by any of the spawn functions.
Any help or pointers to code or docs appreciated.
Thank you,
Devin Nate
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Replacing fork/exec with spawn question
2012-11-25 16:53 Replacing fork/exec with spawn question Devin Nate
@ 2012-11-25 17:14 ` LMH
2012-11-25 18:10 ` Devin Nate
2012-11-25 20:35 ` Christopher Faylor
2012-11-25 19:51 ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
1 sibling, 2 replies; 5+ messages in thread
From: LMH @ 2012-11-25 17:14 UTC (permalink / raw)
To: cygwin
You will need to use windows pipes as well as the windows version of
fork. I have a couple of small apps that do what you are suggesting.
What I did was to abstract the functions for creating process and pipes.
Abstraction was done in the make file. There are functions like
create_new_process(), create_new_pipe(), etc. There are two versions
(posix and windows) of each function with the same name, but in
different src files. When the app is built, one or the other version of
the src file is linked, depending on what os you are in (dual-boot etc).
This lets you build your app on multiple platforms from the same code
base. This could be done with ifdef or other compiler tools as well.
I don't know if I have time today, but I can put together some of the
code for you to look at. Suffice it to say that I have cpp apps that
work as you suggest, parent/child with pipes for IPC, and they were
built for windows using cygwin. They also run under linux if that matters.
It may be better to move such a discussion to a programing board since
some of this will not relate to cygwin and it would be nice to have
things like php formatted code, attachments, etc. The mods here can let
us know about that. I have thought at times that some of the code I have
here should be made into some kind of IPC API. Perhaps others would find
that useful.
LMH
Devin Nate wrote:
> Hi folks,
>
> I'm looking for some documentation about the cygwin spawn use, or a recommendation of a package that has had fork/exec replaced by spawn that I can review to see how someone else did it. Preferably less intimidating than gcc, and which uses pipes for IPC between parent and child.
>
> In particular, the code I'm looking to patch does a typical fork/exec and uses 2 pipes to communicate bi-directionally parent to child. The pipes are throwing me off as to if cygwin spawn is usable.
>
> I've been through the spawn.cc code, and see spawn_guts has a concept of __stdin and __stdout, but I don't see those params used by any of the spawn functions.
>
> Any help or pointers to code or docs appreciated.
>
> Thank you,
> Devin Nate
>
> --
> Problem reports: http://cygwin.com/problems.html
> FAQ: http://cygwin.com/faq/
> Documentation: http://cygwin.com/docs.html
> Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
>
>
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Replacing fork/exec with spawn question
2012-11-25 17:14 ` LMH
@ 2012-11-25 18:10 ` Devin Nate
2012-11-25 20:35 ` Christopher Faylor
1 sibling, 0 replies; 5+ messages in thread
From: Devin Nate @ 2012-11-25 18:10 UTC (permalink / raw)
To: LMH; +Cc: cygwin
Hi LMH,
Fair enough, although I had understood that mixing native Windows functions and cygwin was not a good practice? (Although i have no idea if thats the only option). I will be using ifdefs, and I don't need it abstracted such that I have 2 functions named the same.
I just have a handful of fork/exec's I'd like to fix to be most cygwin friendly.
Thanks,
Devin Nate
On Nov 25, 2012, at 10:14 AM, "LMH" <lmh_users-groups@molconn.com> wrote:
> You will need to use windows pipes as well as the windows version of fork. I have a couple of small apps that do what you are suggesting.
>
> What I did was to abstract the functions for creating process and pipes. Abstraction was done in the make file. There are functions like create_new_process(), create_new_pipe(), etc. There are two versions (posix and windows) of each function with the same name, but in different src files. When the app is built, one or the other version of the src file is linked, depending on what os you are in (dual-boot etc). This lets you build your app on multiple platforms from the same code base. This could be done with ifdef or other compiler tools as well.
>
> I don't know if I have time today, but I can put together some of the code for you to look at. Suffice it to say that I have cpp apps that work as you suggest, parent/child with pipes for IPC, and they were built for windows using cygwin. They also run under linux if that matters.
>
> It may be better to move such a discussion to a programing board since some of this will not relate to cygwin and it would be nice to have things like php formatted code, attachments, etc. The mods here can let us know about that. I have thought at times that some of the code I have here should be made into some kind of IPC API. Perhaps others would find that useful.
>
> LMH
>
> Devin Nate wrote:
>> Hi folks,
>>
>> I'm looking for some documentation about the cygwin spawn use, or a recommendation of a package that has had fork/exec replaced by spawn that I can review to see how someone else did it. Preferably less intimidating than gcc, and which uses pipes for IPC between parent and child.
>>
>> In particular, the code I'm looking to patch does a typical fork/exec and uses 2 pipes to communicate bi-directionally parent to child. The pipes are throwing me off as to if cygwin spawn is usable.
>>
>> I've been through the spawn.cc code, and see spawn_guts has a concept of __stdin and __stdout, but I don't see those params used by any of the spawn functions.
>>
>> Any help or pointers to code or docs appreciated.
>>
>> Thank you,
>> Devin Nate
>>
>> --
>> Problem reports: http://cygwin.com/problems.html
>> FAQ: http://cygwin.com/faq/
>> Documentation: http://cygwin.com/docs.html
>> Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
>>
>>
>
> --
> Problem reports: http://cygwin.com/problems.html
> FAQ: http://cygwin.com/faq/
> Documentation: http://cygwin.com/docs.html
> Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
>
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: Replacing fork/exec with spawn question
2012-11-25 16:53 Replacing fork/exec with spawn question Devin Nate
2012-11-25 17:14 ` LMH
@ 2012-11-25 19:51 ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
1 sibling, 0 replies; 5+ messages in thread
From: Lavrentiev, Anton (NIH/NLM/NCBI) [C] @ 2012-11-25 19:51 UTC (permalink / raw)
To: cygwin
>In particular, the code I'm looking to patch does a typical fork/exec and uses 2 pipes to communicate bi-directionally parent to child. The
>pipes are throwing me off as to if cygwin spawn is usable.
I had no problems using fork/exec on Cygwin, even though it is mentioned to be inefficient in the documentation. If the spawn rate
of your child processes is not high, it should work just well...
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Replacing fork/exec with spawn question
2012-11-25 17:14 ` LMH
2012-11-25 18:10 ` Devin Nate
@ 2012-11-25 20:35 ` Christopher Faylor
1 sibling, 0 replies; 5+ messages in thread
From: Christopher Faylor @ 2012-11-25 20:35 UTC (permalink / raw)
To: cygwin
On Sun, Nov 25, 2012 at 12:13:59PM -0500, LMH wrote:
>It may be better to move such a discussion to a programing board since
>some of this will not relate to cygwin and it would be nice to have
>things like php formatted code, attachments, etc. The mods here can let
>us know about that. I have thought at times that some of the code I have
>here should be made into some kind of IPC API. Perhaps others would find
>that useful.
As a "mod" I can safely say that any topic which discusses how not to
use Cygwin can safely be considered to be off-topic.
However, if you're talking about Cygwin's version of spawn which is (IMO
misguidedly) intended to mimic the spawn* functions in Windows then, if
you are trying to use pipes, you will probably need to investigate how
to use close-on-exec to close one side of the pipe while passing the
other to the subprocess. You should be able to play games with fds
using dup2, dup, and close-on-exec to force a pipe to be the stdin or
stdout of a subprocess. It would be tricky but doable.
http://pubs.opengroup.org/onlinepubs/009695399/functions/fcntl.html
http://pubs.opengroup.org/onlinepubs/009695399/functions/dup2.html
http://msdn.microsoft.com/en-US/library/20y988d2%28v=vs.80%29.aspx
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-11-25 20:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-25 16:53 Replacing fork/exec with spawn question Devin Nate
2012-11-25 17:14 ` LMH
2012-11-25 18:10 ` Devin Nate
2012-11-25 20:35 ` Christopher Faylor
2012-11-25 19:51 ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).