#!/usr/bin/perl -w use strict; use POSIX "WNOHANG"; Main( @ARGV ); exit( 0 ); sub Spawn { my $pid= fork(); die "Can't fork: $!\n" if ! defined $pid; return $pid if $pid; exec( @_ ); die "Can't exec $_[0]: $!\n"; } sub Sleep { my $secs= shift( @_ ); select( undef, undef, undef, $secs ); } sub Main { die qq[Usage: $0 [work wait [nice]] command [args] work Number of seconds to let "command" work at a time [3] wait Number of seconds to make "command" wait inbetween [6] nice Optional command like "nice" or [nice -20]\n] unless @_; unshift @_, qw( 3 6 nice -20 ) unless $_[0] =~ /^\d*\.?\d+$/; my $work= shift( @_ ); my $wait= shift( @_ ); my $kid= Spawn( @_ ); while( $kid != waitpid( $kid, WNOHANG() ) ) { Sleep( $work ); kill 'STOP', $kid; Sleep( $wait ); kill 'CONT', $kid; } exit( $? >> 8 ); }

In reply to breathe - beyond 'nice' by tye

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.