By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,732 Members | 831 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,732 IT Pros & Developers. It's quick & easy.

sending ctrl C to a program

P: n/a
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

Mar 29 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
s9************@yahoo.com wrote:
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.

--
Dale Strickland-Clark
Riverhall Systems - www.riverhall.co.uk
We're recruiting programmers. Please see the web site.

Mar 29 '06 #2

P: n/a
On 2006-03-29, Dale Strickland-Clark <da**@riverhall.nospam.co.uk> 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
visi.com B.C. And I can prove
it too!!
Mar 29 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.