sending ctrl C to a process

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • s99999999s2003@yahoo.com

    #1

    sending ctrl C to a process

    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

  • Felipe Almeida Lessa

    #2
    Re: sending ctrl C to a process

    Em Ter, 2006-03-28 às 18:14 -0800, s99999999s2003@ yahoo.com escreveu:[color=blue]
    > 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?[/color]

    $ python2.4 && echo " **** Python terminates!"
    Python 2.4.2 (#2, Mar 27 2006, 21:07:39)
    [GCC 4.0.3 (Debian 4.0.3-1)] on linux2
    Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
    >>> ^C[/color][/color][/color]
    KeyboardInterru pt[color=blue][color=green][color=darkred]
    >>> try:[/color][/color][/color]
    .... while 1:
    .... pass
    .... except KeyboardInterru pt:
    .... print "\nHey, why did you press Ctrl-C?!"
    .... except:
    .... print "\nStrange. .."
    ....
    ^C
    Hey, why did you press Ctrl-C?![color=blue][color=green][color=darkred]
    >>> import sys
    >>> try:[/color][/color][/color]
    .... while 1:
    .... pass
    .... except KeyboardInterru pt:
    .... sys.exit(0)
    ....
    ^C
    **** Python terminates!
    $

    HTH,

    --
    Felipe.

    Comment

    • s99999999s2003@yahoo.com

      #3
      Re: sending ctrl C to a process

      hi
      thanks for the reply.Actually, i should clarify what i am doing.
      the program's output will be displayed to a web browser using cgi, so
      there is no
      keyboard interrupt. The backend cgi script (python script) will have to
      send Ctrl-C to break the program.
      thanks

      Comment

      • Grant Edwards

        #4
        Re: sending ctrl C to a process

        On 2006-03-29, s99999999s2003@ yahoo.com <s99999999s2003 @yahoo.com> wrote:[color=blue]
        > hi
        > thanks for the reply.[/color]

        Please properly quote the article to which you're replying so
        that we can tell who/what your talking to/about.
        [color=blue]
        > Actually, i should clarify what i am doing. the program's
        > output will be displayed to a web browser using cgi, so there
        > is no keyboard interrupt. The backend cgi script (python
        > script) will have to send Ctrl-C to break the program.[/color]

        Actually, you don't want to send a Ctrl-C to the program. You
        want to send a SIGINT signal to the process. That's what the
        tty line-discipline layer in the tty driver sends to processes
        attached to a tty when the tty receives the interrupt character
        (which defaults to Ctrl-C).

        Sending signals to processes is done using os.kill()



        --
        Grant Edwards grante Yow! How do I get HOME?
        at
        visi.com

        Comment

        Working...