LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to terminate this command (https://www.linuxquestions.org/questions/programming-9/how-to-terminate-this-command-306872/)

slpwkr 03-28-2005 12:23 AM

How to terminate this command
 
Hi guys how can I terminate this command in BASH script.

$ cat /dev/ttyS0

I terminate this commad by using Ctrl c or Ctrl z. But how can I terminate this automatically?

zeropash 03-28-2005 12:52 AM

kill -HUP pid ?

slpwkr 03-28-2005 03:33 AM

Can't do that because the command:

$ cat /dev/ttyS0

will be put into a script file. like this one

!#/bin/sh

$ cat /dev/ttyS0

And I will run script file it cron like every 1 minute. If I will use ps and kill. It will be very complocated because every process has different ps id. I just want to cat and redirect the /dev/ttyS0 every 1 minute but "cat /dev/ttyS0" never stops.

keefaz 03-28-2005 05:35 AM

Execute it in background like :
Code:

cat /dev/ttyS0 &
pid=$!

# wait some time
sleep 2

echo "Now I kill cat /dev/ttyS0"
kill $pid


skie_knite007 03-28-2005 11:33 AM

U can juz use ctrl+ C

or use ps -ax command to kno the process id of the program
Suppose the process ID is 2848.
Now type kill 2648 (from other terminal as root) and the program will be terminated


All times are GMT -5. The time now is 05:16 PM.