473,395 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Kill a Process via a shell script

4
I have a shell script scheduler.sh passing command line arguments start and stop. Below is the code.

Expand|Select|Wrap|Line Numbers
  1. #!/bin/sh
  2. if [ -n $1 ];
  3. then
  4.         perl AD.pl $1;
  5. fi
  6.  
[shap@test]$ sh scheduler.sh stop
If i pass stop the AD.pl file should stop running by killing its pid.
Below is the code for AD.pl when it sees Stop from shell.
Expand|Select|Wrap|Line Numbers
  1. if ($ARGV[0] eq 'stop')
  2. {
  3.     my $cmd = "ps aux | grep " . $0;
  4.     my $result = `$cmd`;
  5.     $log->notice("Stopping Follower $followerName");
  6.     system(`kill -9 $result`);
  7.     $signal = 0;
  8. }
  9.  
Please suggest a cleaner way to above code. is the way i am doing is correct?
Is there a cleaner way of doing it.

Thanks in advance
Sha
Mar 9 '10 #1
3 3036
RedSon
5,000 Expert 4TB
I'm pretty sure the only way to do it is to use the kill command.
Mar 9 '10 #2
numberwhun
3,509 Expert Mod 2GB
You can either issue a shell command in back tics, as RedSon suggested, or, you can use the built in kill command in Perl.

I have not tested it myself, but would certainly test it on something non-production before going live with it.

Regards,

Jeff
Mar 10 '10 #3
RonB
589 Expert Mod 512MB
Cross posted http://perlguru.com/gforum.cgi?post=...=unread#unread
Mar 10 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: John Lin | last post by:
Howdy, I want to know how to tell if a forked process is done. Actually, my real question is that I want to run a shell script inside of a python script, and after the shell script has...
6
by: Bob Swerdlow | last post by:
My application starts up a number of processes for various purposes using: self.popen = popen2.Popen3("/usr/local/bin/python -O "myscript.py") and then shuts them down when appropriate with...
1
by: Alexander N. Spitzer | last post by:
I am trying to write a program that will fork a process, and execute the given task... the catch is that if it runs too long, I want to clean it up. this seemed pretty straight forward with a...
1
by: Manfred Braun | last post by:
Hi All, I am writing a tool, which should monitor some exe-processes, which are not very solid. Th main function is to re-start them, if they hung, but this is complicated. I can detect things...
0
by: WATYF | last post by:
This is my problem... I have some code that starts a Process and returns it to a variable... (prcBat) At any time while that process is running... I want to be able to Kill it by pressing a...
3
by: elrondrules | last post by:
Hi Am new to python and need your help!! this is my code snip. within my python script I have the following commands.. <snip> import os
4
by: Richard Rossel | last post by:
Hi Fellows, I have a problem with process termination. I have a python code that apache runs through a django interface. The code is very simple, first, it creates a process with the...
2
by: deciacco | last post by:
I have a NotifyIcon application. (c# 2) I want to be able to catch a kill/shutdown attempt so that I can call Dispose() to remove the icon. I tried to create an event handler for ApplicationExit...
1
by: chengiz | last post by:
Hi, I'm trying to run a process from a python script. I need the exit status of that process but do not care about its output, so until now was using os.system(). But it turned out that the...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.