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

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;








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?










share|improve this question






















  • That code you posted doesn't run, much less demonstrate the problem. Please fix your question.

    – ikegami
    Mar 26 at 6:27


















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?










share|improve this question






















  • That code you posted doesn't run, much less demonstrate the problem. Please fix your question.

    – ikegami
    Mar 26 at 6:27














0












0








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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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













1 Answer
1






active

oldest

votes


















2














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;






share|improve this answer

























  • Thank you, it works with the workaround.

    – Igor Dvorzhak
    Mar 26 at 16:34










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
);



);













draft saved

draft discarded


















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









2














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;






share|improve this answer

























  • Thank you, it works with the workaround.

    – Igor Dvorzhak
    Mar 26 at 16:34















2














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;






share|improve this answer

























  • Thank you, it works with the workaround.

    – Igor Dvorzhak
    Mar 26 at 16:34













2












2








2







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;






share|improve this answer















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;







share|improve this answer














share|improve this answer



share|improve this answer








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

















  • 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








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.



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript