#!/usr/bin/perl use strict; use warnings; use Gtk; use Socket; use IO::Handle; use Getopt::Long; MAIN: { my $window; my $button; my $pid; my %opts; my $at_start = 2; my $at_end = 2; my $fork = 2; GetOptions("at_start!" => \$at_start, "at_end!" => \$at_end, "fork!" => \$fork); if (2 == $at_start && 2 == $at_end) { print "You must select start or end\n"; exit; } if (1 == $at_start) { print "Calling at start\n"; set_locale Gtk; init Gtk; } if (1 == $fork) { socketpair(CHILD, PARENT, Socket::AF_UNIX, Socket::SOCK_STREAM, Socket::PF_UNSPEC) or die "socketpair: $!"; CHILD->autoflush(1); PARENT->autoflush(1); my $line; if ($pid = fork) { close PARENT; print CHILD "Parent Pid $$ is sending this\n"; chomp($line = ); print "Parent Pid $$ just read this: `$line'\n"; close CHILD; waitpid($pid,0); } else { die "cannot fork: $!" unless defined $pid; close CHILD; chomp($line = ); print "Child Pid $$ just read this: `$line'\n"; print PARENT "Child Pid $$ is sending this\n"; close PARENT; exit; } } if (1 == $at_end) { print "Calling at end\n"; set_locale Gtk; init Gtk; } print("got here\n"); $window = new Gtk::Window("toplevel"); print("got there\n"); $window->signal_connect("destroy", sub { Gtk->exit(0) }); $window->set_title("testing"); $button = new Gtk::Button("Quit"); $button->signal_connect("clicked", sub { Gtk->exit(0) }); $window->add($button); $window->show_all; main Gtk; }