Richard Evans - 2003-01-09

Hi everyone

Before I start, happy New Year - lets hope this will be a good year for PerlQt :)

This post is a little OT, but if anyone has any comments, they will be gratefully received.

I want to launch a text editor (kedit, kate etc) from my PerlQt app, so I'm using the usual fork, exec stuff - this is an excerpt which will hopefully look ok when posted:

defined(my $pid = fork) or

if ( $pid )
  debug("parent($$) launched child($pid)") if DEBUG;
  exec({$_[0]} @_) or kill 9 => $$;

Does the exec line seem ok? I've tried alternatives such as:

  exec({$_[0]} @_) or die "exec failed: $!";


  exec({$_[0]} @_) or CORE::exit(1);

But in each case if exec() fails, I get X error messages such as:

Can't exec "/usr/lib/perl5/vendor_perl/Ridas/": Permission denied at /usr/lib/perl5/vendor_perl/Ridas/ line 189.
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
  Major opcode:  62
  Resource id:  0x36000a4
X Error: 179 179
  Major opcode:  152
  Resource id:  0x36000a5
X Error: BadPixmap (invalid Pixmap parameter) 4
  Major opcode:  54
  Resource id:  0x36000a4
X Error: BadIDChoice (invalid resource ID chosen for this connection) 14
  Major opcode:  55
  Resource id:  0x360016d

The CORE::exit version also seems to kill off the parent process.
So, brushing off my UNIX process control knowledge, when the fork occurs there are two identical copies of the process. I presume if the child makes any attempt to access a Qt/X resource the errors I'm seeing will occur. Since I wrap the code excerpt above in an eval{} higher up, I can understand why calling die() might not work, but I'm not sure why CORE::exit() causes problems.

The kill 9 => $$ version appears to work fine - no X errors and the parent continues without problem when the child exec fails for some reason.

Can anyone tell me if I'm handling this correctly, or do the errors I've been getting suggest I have problems elsewhere? I'm neither an expert on Qt or UNIX process control (as I'm sure you've guessed by this post :), so any feedback would be much appreciated.