The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-01-2004
sharuvman sharuvman is offline
Registered User
  
 

Join Date: Mar 2002
Location: Bangalore,Karnataka State,India
Posts: 18
Red face Killing a process from perl script.

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
  #2 (permalink)  
Old 04-01-2004
TioTony's Avatar
TioTony TioTony is offline Forum Advisor  
Bit Pusher
  
 

Join Date: Oct 2001
Location: Southern California
Posts: 332
I don't think you have provided enough info for anyone to help you. The command you listed looks more like something you would run from command line or in a ksh, bash, sh, or csh shell script. It definitely does not look like perl to me. Perl has it's own process handling functions which you should check into.
  #3 (permalink)  
Old 04-01-2004
sharuvman sharuvman is offline
Registered User
  
 

Join Date: Mar 2002
Location: Bangalore,Karnataka State,India
Posts: 18
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
  #4 (permalink)  
Old 04-01-2004
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
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";
}
...
...

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0