I have a simple but ugly script that reminds me of things I need help remembering.
#!/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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.