Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

perl process questions

perl process questions

perl process questions

Hi! I created the following perl subroutine to prevent multiple occurrances of the same script from running.
I supply a maximum task count due to the subprocesses perl seems to create for things like globs and the actual grep task!
I now would like to kill any previous running occurrances of the script. Given the subprocesses perl creates, it there a best way to do this? For example, if  I kill the main perl task, will the child processes die gracefully?
I know they will become defunct, but will they also be removed from the process table on Solaris? Or do I need to kill all the child processes first?
Any and all suggestions are welcome!

sub process_ck{
        my $mcount = $_[0]; # max task count
        my $parm = $0;
       chomp(my @procs = qx!ps -aux¬¶grep '$parm'!);
        my ($count, $element);
        foreach (@procs){
                if (index($_, $parm) ne -1){
        if ($count > $mcount){
                die "Task $parm already running!\n";

RE: perl process questions

Hi dabits,

Just running a Perl script doesn't create child processes - so unless you're explicitly calling fork() in your scripts you can just kill the Perl process.

A common way to make sure you're only running one copy of a process in Unix is to create a lock file - on startup check for the existence of a particular file, '/tmp/myprog.lock' for instance, if it's there your prog is already running. If it's not - create it and write your process ID (that's $$) to the file and close it.

Cargill's Corporate Web Site

RE: perl process questions

Don't kill your processes if you're using mod-perl!  It keeps open a bunch of processes so that it doesn't have to reinitialize the perl interpreter every time, thus making things much faster.  Otherwise, Perl generally cleans up after itself.


Tom Anderson
CEO, Order amid Chaos, Inc.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close