How do I block ctrl-c to a command executed from the shell?

How do I block ctrl-c to a command executed from the shell?

Post by Sandeep Gup » Mon, 06 Jan 2003 06:52:07



How do I block ctrl-c to a command executed from the shell?

For example, suppose I am calling "cvs diff" and want to prevent it
from being interrupted.

I tried:
cvs diff < /dev/null
But the ctrl-c still goes through.  Is there any way to do this?

Thanks

 
 
 

How do I block ctrl-c to a command executed from the shell?

Post by Kenny McCorma » Mon, 06 Jan 2003 07:32:08




>How do I block ctrl-c to a command executed from the shell?

>For example, suppose I am calling "cvs diff" and want to prevent it
>from being interrupted.

>I tried:
>cvs diff < /dev/null
>But the ctrl-c still goes through.  Is there any way to do this?

>Thanks

trap '' 2

or

stty intr ""

 
 
 

How do I block ctrl-c to a command executed from the shell?

Post by Oscar del Ri » Mon, 06 Jan 2003 07:43:04



Quote:> How do I block ctrl-c to a command executed from the shell?

You have to "trap" the signal.
If your shell is sh or bash you can try for example
(trap "" 2 3; sleep 10)

For csh or tcsh:
(onintr -; sleep 10)

Control-C will not kill the "sleep 10" command

 
 
 

How do I block ctrl-c to a command executed from the shell?

Post by Erik Max Franci » Mon, 06 Jan 2003 15:08:27



> How do I block ctrl-c to a command executed from the shell?

> For example, suppose I am calling "cvs diff" and want to prevent it
> from being interrupted.

> I tried:
> cvs diff < /dev/null
> But the ctrl-c still goes through.  Is there any way to do this?

Deja vu :-).

--

 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ We'll have to make our own luck from now on.
\__/ Louis Wu
    Bosskey.net: Quake III Arena / http://www.bosskey.net/q3a/
 A personal guide to Quake III Arena.

 
 
 

1. blocking CTRL-Z and CTRL-C

: how in C or at the % prompt do I block the use of ctrl-z and ctrl-c while
: and only while my program is running?

You want to catch signals 24 (SIGTSTP for ctrl-z) and 2 (SIGINT
for ctrl-c).

For example:

#include <signal.h>

{
    ....
    signal (SIGTSTP,my_sig_func);
    signal (SIGINT,my_sig_func);
    ....

void my_sig_func(int signum)
{
   printf("Caught signal %d.\n",signum);

--Mike
--

' ) ) )   /       /  )        /   "True nervous, very, very, dreadfully
 / / / o /_  _   /    _  o __/ _  _ nervous I have been and am, but why
/ ' (_/_/ <_(/_ (__/ /(_/_(_/_(/_/(_ will you say that I am mad?"

2. Joining subnets

3. Why does CTRL-C on CTRL-Z kill my shell and log me out?

4. which xserver 4 a diamond stealth 1000?

5. problem with executing commands from within the shell using a command string.

6. Installing Linux on an IBM PS/1

7. emacs shell-command-on-region command can't execute on Slackware.

8. Looking for info on a program called ICAO

9. how to invoke another shell inside an shell and then execute the command

10. ctrl-c command

11. ctrl-c doesn't work, ps command sources

12. Executing a command in "non-blocking" mode?

13. How do you execute an rdist special command after everything's done?