sending ctrl C to a program

S

s99999999s2003

hi
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
 
D

Dale Strickland-Clark

hi
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?

So something like

import os
os.kill(1234, 2)

would send ctrl-c to process 1234.

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

Grant Edwards

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top