Store multiple items in IPC::ShareLite objectThe difference between fork(), vfork(), exec() and clone()Notify multiple listeners after an object changesWhat is the preferred cross-platform IPC Perl module?IPC::Shareable store hash of hashesShould we detach shared memory before termination of a forked processMessage queue for IPC with fork and want to know whether the processes 'share' the message buffer or just copy and 'show' to the other processshared queue between multiple process in perlIPC between C application and PythonPassing Python object to another Python processHow to create an ipc communication win-form within a project
Multi tool use
Doing research in academia and not liking competition
What is this welding tool I found in my attic?
What are some symbols representing peasants/oppressed persons fighting back?
Can I intentionally omit previous work experience or pretend it doesn't exist when applying for jobs?
How do a planet's moons and a planet's rings interact?
Data standardization vs. normalization for clustering analysis
What is temperature on a quantum level?
Cubic programming and beyond?
Why would an Inquisitive rogue choose to use Insightful Fighting as opposed to using their Cunning Action to Hide?
CPU overheating in Ubuntu 18.04
Too many spies!
Is `curl something | sudo bash -` a reasonably safe installation method?
Professor falsely accusing me of cheating in a class he does not teach, two months after end of the class. What precautions should I take?
Why is dry soil hydrophobic? Bad gardener paradox
Alternatives to using writing paper for writing practice
How do I write a romance that doesn't look obvious
Would letting a multiclass character rebuild their character to be single-classed be game-breaking?
What is the German equivalent of 干物女 (dried fish woman)?
Report how much space is used and available in storage in ZFS on FreeBSD
Find the wrong number in the given series: 6, 12, 21, 36, 56, 81?
Was adding milk to tea started to reduce employee tea break time?
Supporting developers who insist on using their pet language
Why does the autopilot disengage even when it does not receive pilot input?
How does one stock fund's charge of 1% more in operating expenses than another fund lower expected returns by 10%?
Store multiple items in IPC::ShareLite object
The difference between fork(), vfork(), exec() and clone()Notify multiple listeners after an object changesWhat is the preferred cross-platform IPC Perl module?IPC::Shareable store hash of hashesShould we detach shared memory before termination of a forked processMessage queue for IPC with fork and want to know whether the processes 'share' the message buffer or just copy and 'show' to the other processshared queue between multiple process in perlIPC between C application and PythonPassing Python object to another Python processHow to create an ipc communication win-form within a project
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a Perl program that forks subprocesses and processes N items in them, after that I need to return these processed items to main process.
From multiple available IPC options to return processed items to main process, IPC::ShareLite seems to be a simplest one, but I'm not sure if it supports storing multiple items in one shared object.
Here is a snippet from the program, but it doesn't work:
use IPC::ShareLite;
# create shared object in main process
my $share = new IPC::ShareLite(
-key => 1234,
-create => 'yes',
-destroy => 'yes'
) or die $!;
# fork subprocesses, process and store N items in shared object
$share->store($member);
# After subprocesses finish, fetch items in main process
my $members_size = scalar @$members_ref;
@$members_ref = ();
while ($members_size > 0)
my $member = $share->fetch();
push @$members_ref, $member;
$members_size--;
Above code fails with quite obscure error on my $member = $share->fetch();
:
IPC::ShareLite fetch() error: Invalid argument at ...
Is it possible to use IPC::ShareLite object as I intend or it can hold only one item?
perl fork ipc
add a comment |
I have a Perl program that forks subprocesses and processes N items in them, after that I need to return these processed items to main process.
From multiple available IPC options to return processed items to main process, IPC::ShareLite seems to be a simplest one, but I'm not sure if it supports storing multiple items in one shared object.
Here is a snippet from the program, but it doesn't work:
use IPC::ShareLite;
# create shared object in main process
my $share = new IPC::ShareLite(
-key => 1234,
-create => 'yes',
-destroy => 'yes'
) or die $!;
# fork subprocesses, process and store N items in shared object
$share->store($member);
# After subprocesses finish, fetch items in main process
my $members_size = scalar @$members_ref;
@$members_ref = ();
while ($members_size > 0)
my $member = $share->fetch();
push @$members_ref, $member;
$members_size--;
Above code fails with quite obscure error on my $member = $share->fetch();
:
IPC::ShareLite fetch() error: Invalid argument at ...
Is it possible to use IPC::ShareLite object as I intend or it can hold only one item?
perl fork ipc
That code you posted doesn't run, much less demonstrate the problem. Please fix your question.
– ikegami
Mar 26 at 6:27
add a comment |
I have a Perl program that forks subprocesses and processes N items in them, after that I need to return these processed items to main process.
From multiple available IPC options to return processed items to main process, IPC::ShareLite seems to be a simplest one, but I'm not sure if it supports storing multiple items in one shared object.
Here is a snippet from the program, but it doesn't work:
use IPC::ShareLite;
# create shared object in main process
my $share = new IPC::ShareLite(
-key => 1234,
-create => 'yes',
-destroy => 'yes'
) or die $!;
# fork subprocesses, process and store N items in shared object
$share->store($member);
# After subprocesses finish, fetch items in main process
my $members_size = scalar @$members_ref;
@$members_ref = ();
while ($members_size > 0)
my $member = $share->fetch();
push @$members_ref, $member;
$members_size--;
Above code fails with quite obscure error on my $member = $share->fetch();
:
IPC::ShareLite fetch() error: Invalid argument at ...
Is it possible to use IPC::ShareLite object as I intend or it can hold only one item?
perl fork ipc
I have a Perl program that forks subprocesses and processes N items in them, after that I need to return these processed items to main process.
From multiple available IPC options to return processed items to main process, IPC::ShareLite seems to be a simplest one, but I'm not sure if it supports storing multiple items in one shared object.
Here is a snippet from the program, but it doesn't work:
use IPC::ShareLite;
# create shared object in main process
my $share = new IPC::ShareLite(
-key => 1234,
-create => 'yes',
-destroy => 'yes'
) or die $!;
# fork subprocesses, process and store N items in shared object
$share->store($member);
# After subprocesses finish, fetch items in main process
my $members_size = scalar @$members_ref;
@$members_ref = ();
while ($members_size > 0)
my $member = $share->fetch();
push @$members_ref, $member;
$members_size--;
Above code fails with quite obscure error on my $member = $share->fetch();
:
IPC::ShareLite fetch() error: Invalid argument at ...
Is it possible to use IPC::ShareLite object as I intend or it can hold only one item?
perl fork ipc
perl fork ipc
asked Mar 26 at 5:56
Igor DvorzhakIgor Dvorzhak
1,7761 gold badge11 silver badges21 bronze badges
1,7761 gold badge11 silver badges21 bronze badges
That code you posted doesn't run, much less demonstrate the problem. Please fix your question.
– ikegami
Mar 26 at 6:27
add a comment |
That code you posted doesn't run, much less demonstrate the problem. Please fix your question.
– ikegami
Mar 26 at 6:27
That code you posted doesn't run, much less demonstrate the problem. Please fix your question.
– ikegami
Mar 26 at 6:27
That code you posted doesn't run, much less demonstrate the problem. Please fix your question.
– ikegami
Mar 26 at 6:27
add a comment |
1 Answer
1
active
oldest
votes
You are creating a child using fork
, and this child gets a copy of the $share
object. When the child exits, the child's copy of the $share
object is destroyed, which causes the underlying system resources to be destroyed because you used -destroy => 'yes'
.
In general, you want to create objects with destructors after performing the forks.
But when creating a IPC::ShareLite object, you normally want to leave key to let the system choose the key for you, but you need to do that before creating the forks.
Workaround
Perform the following in the child:
$share->destroy(0);
A better solution
Since the a normal usage mode for the module involves creating an object inherited by child processes, the module should handle that situation.
To that end, you should have the module's maintainer change the module so that the destruction only occurs if the current PID is the same as the PID in which $share
was created.
sub _initialize
...
$self->pid = $$; # ADD
...
sub DESTROY
my $self = shift;
#destroy_share( $self->share, $self->destroy ) # REMOVE
destroy_share( $self->share, $self->pid == $$ ? $self->destroy : 0 ) # ADD
if $self->share;
Thank you, it works with the workaround.
– Igor Dvorzhak
Mar 26 at 16:34
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55350668%2fstore-multiple-items-in-ipcsharelite-object%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are creating a child using fork
, and this child gets a copy of the $share
object. When the child exits, the child's copy of the $share
object is destroyed, which causes the underlying system resources to be destroyed because you used -destroy => 'yes'
.
In general, you want to create objects with destructors after performing the forks.
But when creating a IPC::ShareLite object, you normally want to leave key to let the system choose the key for you, but you need to do that before creating the forks.
Workaround
Perform the following in the child:
$share->destroy(0);
A better solution
Since the a normal usage mode for the module involves creating an object inherited by child processes, the module should handle that situation.
To that end, you should have the module's maintainer change the module so that the destruction only occurs if the current PID is the same as the PID in which $share
was created.
sub _initialize
...
$self->pid = $$; # ADD
...
sub DESTROY
my $self = shift;
#destroy_share( $self->share, $self->destroy ) # REMOVE
destroy_share( $self->share, $self->pid == $$ ? $self->destroy : 0 ) # ADD
if $self->share;
Thank you, it works with the workaround.
– Igor Dvorzhak
Mar 26 at 16:34
add a comment |
You are creating a child using fork
, and this child gets a copy of the $share
object. When the child exits, the child's copy of the $share
object is destroyed, which causes the underlying system resources to be destroyed because you used -destroy => 'yes'
.
In general, you want to create objects with destructors after performing the forks.
But when creating a IPC::ShareLite object, you normally want to leave key to let the system choose the key for you, but you need to do that before creating the forks.
Workaround
Perform the following in the child:
$share->destroy(0);
A better solution
Since the a normal usage mode for the module involves creating an object inherited by child processes, the module should handle that situation.
To that end, you should have the module's maintainer change the module so that the destruction only occurs if the current PID is the same as the PID in which $share
was created.
sub _initialize
...
$self->pid = $$; # ADD
...
sub DESTROY
my $self = shift;
#destroy_share( $self->share, $self->destroy ) # REMOVE
destroy_share( $self->share, $self->pid == $$ ? $self->destroy : 0 ) # ADD
if $self->share;
Thank you, it works with the workaround.
– Igor Dvorzhak
Mar 26 at 16:34
add a comment |
You are creating a child using fork
, and this child gets a copy of the $share
object. When the child exits, the child's copy of the $share
object is destroyed, which causes the underlying system resources to be destroyed because you used -destroy => 'yes'
.
In general, you want to create objects with destructors after performing the forks.
But when creating a IPC::ShareLite object, you normally want to leave key to let the system choose the key for you, but you need to do that before creating the forks.
Workaround
Perform the following in the child:
$share->destroy(0);
A better solution
Since the a normal usage mode for the module involves creating an object inherited by child processes, the module should handle that situation.
To that end, you should have the module's maintainer change the module so that the destruction only occurs if the current PID is the same as the PID in which $share
was created.
sub _initialize
...
$self->pid = $$; # ADD
...
sub DESTROY
my $self = shift;
#destroy_share( $self->share, $self->destroy ) # REMOVE
destroy_share( $self->share, $self->pid == $$ ? $self->destroy : 0 ) # ADD
if $self->share;
You are creating a child using fork
, and this child gets a copy of the $share
object. When the child exits, the child's copy of the $share
object is destroyed, which causes the underlying system resources to be destroyed because you used -destroy => 'yes'
.
In general, you want to create objects with destructors after performing the forks.
But when creating a IPC::ShareLite object, you normally want to leave key to let the system choose the key for you, but you need to do that before creating the forks.
Workaround
Perform the following in the child:
$share->destroy(0);
A better solution
Since the a normal usage mode for the module involves creating an object inherited by child processes, the module should handle that situation.
To that end, you should have the module's maintainer change the module so that the destruction only occurs if the current PID is the same as the PID in which $share
was created.
sub _initialize
...
$self->pid = $$; # ADD
...
sub DESTROY
my $self = shift;
#destroy_share( $self->share, $self->destroy ) # REMOVE
destroy_share( $self->share, $self->pid == $$ ? $self->destroy : 0 ) # ADD
if $self->share;
edited Mar 26 at 7:04
answered Mar 26 at 6:37
ikegamiikegami
275k11 gold badges194 silver badges415 bronze badges
275k11 gold badges194 silver badges415 bronze badges
Thank you, it works with the workaround.
– Igor Dvorzhak
Mar 26 at 16:34
add a comment |
Thank you, it works with the workaround.
– Igor Dvorzhak
Mar 26 at 16:34
Thank you, it works with the workaround.
– Igor Dvorzhak
Mar 26 at 16:34
Thank you, it works with the workaround.
– Igor Dvorzhak
Mar 26 at 16:34
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55350668%2fstore-multiple-items-in-ipcsharelite-object%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
dx zxLA2t4KvbR9cmjoaxUo,DM vEkky,Xt8oABjGW u,lnd2dRAmE,Tx
That code you posted doesn't run, much less demonstrate the problem. Please fix your question.
– ikegami
Mar 26 at 6:27