#!/usr/bin/perl -w #reminder.plx use strict; use Data::Dumper; $/ = "#-"; open(INFILE, "/foo/reminder.txt") or die "Can't open reminders.txt: $! +"; my @reminders = <INFILE>; my $random = rand(@reminders); my $reminder = $reminders[$random]; $reminder =~ s/\d\. //g; chomp $reminder; my $pid; # From here on down is the part I don't like, although it doe +s do what I want it to do. defined ($pid = fork()) or die $!; if ($pid==0) { $pid and last; exec ("/usr/bin/zenity --display=:0.0 --info --title='Reminder' --text +='$reminder' &") or die "Something went wrong:$!"; } my $retval; sleep 100; $pid++; kill 15, $pid;
The part that bothers me is the bit that finds the pid of zenity and kills it. I couldn't figure out/find a better way of finding the pid. The method I used seems to find the pid just before (numerically speaking) my zenity dialog, so I used $pid++ to get the pid I wanted, but this seems dangerous for reasons you probably understand better than I do. I'd appreciate any helpful suggestions on how to improve this script, especially the part I've just described.
I'm using Ubuntu linux btw.In reply to Finding the PID of zenity in a perl script. by HappyTimeHarry
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |