Exforsys
+ Reply to Thread
Results 1 to 2 of 2

Want to Kill the Process

This is a discussion on Want to Kill the Process within the Shell Programming forums, part of the Operating Systems category; My shell script has a main program that runs as a main parent. There are many scripts called from this ...

  1. #1
    Ralph is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    114

    Want to Kill the Process

    My shell script has a main program that runs as a main parent. There are many scripts called from this main parent process. Each of these child process returns to the parent after execution. But I want to kill the child process before it returns to the main parent program. I am struck with this step. Someone provide me suggestions for doing this.


  2. #2
    rachelle is offline Member Array
    Join Date
    Apr 2006
    Answers
    97
    Each process has a process id associated with it. It is this process id which will help us in deleting the process or accessing the process a user requires. For your requirement first you must get the process id of the last background process. This can be got by using the command $!.The command returns the process id of the last background process. Also get the process id of the current process in execution using the command $$. Now to kill the child process after its execution and return to your main process use the command kill -1 followed by the process id of the last background process stored in $!. Give this in the main process and your last child process would get killed.


Latest Article

Network Security Risk Assessment and Measurement

Read More...