You are not logged in.

#1 2011-08-30 21:09:51

ying
Member
From: Austria
Registered: 2010-03-02
Posts: 110

C/C++ fork function but without copying members

HI all
I know fork and vfork. But I am looking for a fork similar command, which does not copy any members from the parent process, but instead creates them how they are at a fresh program startup.

THX

Offline

#2 2011-08-30 21:38:12

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: C/C++ fork function but without copying members

members? Are you referring to the memory space? fork usually implements the memory "duplication" as copy-on-write, meaning that the new process shares the same physical pages until you write to them. If you're looking to micro-optimize someting in the fork call, you won't find it here. memset whatever it is you're trying to get as "fresh".

If you need absurdly fine grained control, use clone. still, i don't think you're able to avoid the CoW behavior, but I really can't think of a reason why you'd want to explicitly avoid this.

Offline

#3 2011-08-30 21:57:05

ying
Member
From: Austria
Registered: 2010-03-02
Posts: 110

Re: C/C++ fork function but without copying members

HI thx for your answer. The problem is this: I have a function which creates a new process with fork and then it shows up a gui widget. K all fine. But when I want to create another gui widget out of the current process, so the first gui widget, then I can't show up the new gui widget, because a QApplication event loop is already running. Actually that is only copied by fork.^^ That is a short explanation of my problem.

Last edited by ying (2011-08-30 21:57:55)

Offline

#4 2011-08-30 22:00:30

tavianator
Member
From: Waterloo, ON, Canada
Registered: 2007-08-21
Posts: 859
Website

Re: C/C++ fork function but without copying members

Why do you want to do this?

Anyway, use fork() + exec(argv[0], ...), or posix_spawn(..., argv[0], ...).  But more than likely, the best option is a redesign.

Offline

#5 2011-08-30 22:06:31

ying
Member
From: Austria
Registered: 2010-03-02
Posts: 110

Re: C/C++ fork function but without copying members

It is very complicated to explain, why I need this. It works in combination with more than one X Server session...

tavianator wrote:

Anyway, use fork() + exec(argv[0], ...), or posix_spawn(..., argv[0], ...).  But more than likely, the best option is a redesign.

That won't help me. I think I could manager it with the SIGUSR1 signal.

Last edited by ying (2011-08-30 22:15:58)

Offline

Board footer

Powered by FluxBB