<div dir="ltr">Hi Frederic,<div><br></div><div>Let me give a high level recommendation: don't use forkProcess. It's a very dangerous function, which can result in confusing behavior and impossible-to-debug problems. There are cases where it can be made to work, but (1) it's complicated, (2) I'm not sure anyone has ever figured out all of those caveats, and (3) it's certainly not documented properly.</div><div><br></div><div>forkProcess is little more than a call to the fork() system call, creating a brand new child process which will run the IO action provided. The runtimes of the two processes will not be connected to each other at all. It would be impossible to, say, throw an exception from a thread in the parent process to a thread in the child process.</div><div><br></div><div>I could say a lot more about this, but I think I'll just reiterate my original recommendation: don't use forkProcess :)</div><div><br></div><div>Instead, for this kind of use case of changing user/group IDs, I'd recommend using a normal external process call via the process package[1]. I'm not sure of your use case exactly, but I see three ways of making this work:</div><div><br></div><div>* Generate two Haskell executables</div><div>* Put the code for both the parent and child into a single executable, and use command line arguments or env vars to control which behavior is run</div><div>* If you don't have any real logic in the Haskell code, and instead are just using some other program: you can call that directly</div><div><br></div><div>HTH,</div><div>Michael</div><div><br></div><div>[1] Or the typed-process package instead, which I typically recommend these days. Note that I'm the maintainer of process, but typed-process has a brand new API I think is easier to use correctly. More info at: <a href="https://haskell-lang.org/library/typed-process">https://haskell-lang.org/library/typed-process</a></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Jul 17, 2018 at 3:36 PM PICCA Frederic-Emmanuel <<a href="mailto:frederic-emmanuel.picca@synchrotron-soleil.fr">frederic-emmanuel.picca@synchrotron-soleil.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I try to write a service which execute an IO using forkProcess<br>
This service contain a web server whcih avwait for job published by users.<br>
for each job, I create a forkProcess of this job. I need to fork the process in order to change the uid and gid of the process for each of the job dependencing on who request the job.<br>
<br>
I have a least two questions<br>
<br>
1) is this forkProcess a fork of all the current process, or is it just an executin of the IO in another process id ?<br>
<br>
I ask this because sometime one of my job hang and a process keep running. Since the original process is binded to a port, it is not possible to restart the server, saying that the port is already in use.<br>
<br>
2 ) How can I catch the exceptions thrown from the child process in order to process them in the parent process.<br>
<br>
thanks for your help answering these questions.<br>
<br>
<br>
Frederic<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div>