in reply to How to kill a process redirected to /dev/null
If you wan't to kill monitor.pl (if it's running) from a separate script, this should work:
#! /usr/bin/perl use strict; use warnings; my $list = `ps -a`; print STDERR "$list"; my @processLine; my @processesArray = split("\n", $list); print STDERR "$processesArray[0]\n"; for (@processesArray) { if ($_ =~ m/monitor.pl/) { @processLine = split(" ", $_); system ("kill $processLine[0]"); print STDERR "$processLine[$#processLine] killed.\n"; } }
On *nix systems at least, because the OS processes the command line before running the original script (ie. "monitor.pl > /dev/null"), I don't know of a way to distinguish instances of a script based on their redirection targets.
I hope that helps.
|
|---|