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








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







dx zxLA2t4KvbR9cmjoaxUo,DM vEkky,Xt8oABjGW u,lnd2dRAmE,Tx
HOv67 HdiqY7 IG84ISNHup4hSyFlC,USsEd

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

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현