![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Killing of a process and send a mail if the process doesnot come up within 2 minutes | Prince89 | Shell Programming and Scripting | 1 | 02-15-2008 07:10 PM |
| While killing the process, Script gets hanged. Please help me on this. | Sheethal | Shell Programming and Scripting | 8 | 10-11-2007 10:50 AM |
| killing a process from a script | jalge2 | AIX | 4 | 01-19-2006 10:46 AM |
| Perl: Run perl script in the current process | vino | Shell Programming and Scripting | 10 | 12-09-2005 10:45 AM |
| killing process using a script | skotapal | Shell Programming and Scripting | 4 | 12-12-2002 04:05 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How do I kill a process, say by name "drec" from a perl script.
I tried with : ps -eaf | grep drec | awk '{print $2}' | xargs kill -9. The output I got is : ps -eaf | grep drec | awk '{print }' | xargs kill -9 /usr/bin/kill[8]: ipgen: Arguments must be %job or process ids {But, $2 is not getting seen.} Same thing worked from a shell script. Thanks, Sharath |
|
||||
|
Sorry for incomplete question, Tony.
I was using perl's expect module to login to a machine and grep for the process and kill it. That is when I faced this problem. Now I am using cut command to kill the process and it is working fine. But I am not satisfied with the cut command's way of handling my problem as I am using as below : $cmd = "ps -eaf | grep drec | grep -v grep | cut -c10-15 | xargs kill -9"; print $log " $cmd\n"; This is solving my problem temporarily. But I want a permanent solution. Sharath |
|
||||
|
try to avoid all the exec calls to the shell. they will take a toll on your perl program. This is a snipit from Learning Perl section 14.7. Sending and Receiving Signals Code:
[328]Sending a signal will also fail if you're not the superuser and it's someone else's process. It would be rude to send SIGINT to someone else's programs, anyway.
unless (kill 0, $pid) {
warn "$pid has gone away!";
}
altho i dont kill a remote process i do kill my local process like so. i know there are other modules out there to handle what i am trying to do but this seems to work for now. Code:
...
...
if (-f "/tmp/ftp_out.pid") {
open (PIDFILE, "/tmp/ftp_out.pid");
chomp(my $PID=<PIDFILE>);
if (grep /$PID/, `ps -p $PID`) { close (PIDFILE); die "$0 is already running.\n"
; };
unlink "/tmp/ftp_out.pid";
}
...
...
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|