skip to Main Content

This might be a very basic question but I couldn’t find it anywhere on the internet.
Lets assume I have a file named test with this code

echo hello
sleep 10
echo hello
sleep 10
echo hello
sleep 10

How would I go about killing that program through another terminal in my server?

3

Answers


  1. Ctrl c
    

    By Pressing this, you can kill that program from your terminal.
    And you can kill this program from your main terminal where you exicute this in first place.

    Login or Signup to reply.
  2. I am assuming the file is test.sh

    You can do:

    ps -x | grep ./test.sh
    

    This will show the processes:

    11164 pts/1    S+     0:00 /usr/bin/bash ./test.sh
    and a second process that will be a grep process, you won't be able to kill the process that has the word grep in it because that process completes right away
    

    now you can kill the process using the PID:

    kill 11164
    
    Login or Signup to reply.
  3. Your script filename is test.

    So, in another terminal, you can execute ps aux | grep test.

    Then you can get the PID of test, which is located at the second column.

    Then, execute kill -9 <PID>.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search