sending ctrl C to a program

Grant Edwards grante at
Wed Mar 29 17:12:29 CEST 2006

On 2006-03-29, Dale Strickland-Clark <dale at> wrote:

>> i have a program that works very similar to tail -f in Unix It
>> will need a Ctrl-C in order to break out of the program. I
>> wish to run this program using python (either thru os.system()
>> or some other subprocess modules) and how can i pass Ctrl-C to
>> this program to terminate it in python? thanks
> Isn't SIGINT the same as ctrl-c?

SIGINT is what the tty line discipline layer sends to the
attached processes when it sees a receive interrupt character
and canonical mode is enabled.  By default the interrupt
character is ctrl-C.

> So something like 
> import os
> os.kill(1234, 2)
> would send ctrl-c to process 1234.

That is, indeed, what the OP wants to do.  Except there is no
ctrl-C involved.  That code is doing what the tty line
discipline code does when _it_ see's a ctrl-C.

> If you just want the process to quit, you could probably just
> send it a SIGTERM, which is signal 15.

Grant Edwards                   grante             Yow!  My uncle Murray
                                  at               conquered Egypt in 53
                                 B.C. And I can prove
                                                   it too!!

More information about the Python-list mailing list