Trap command from C program? [duplicate]
This question already has an answer here:
Catch Ctrl-C in C
9 answers
I'd like to run a trap '' 2
command from a C program to prevent ctrl-c
when the a.out
is run.
#define TRAP "trap '' 2"
int main()
{
system(TRAP);
...
}
I can get it to work from a .sh
file that also runs the program but I'd like everything to be in one .c
file.
trap '' 2
cd /Users/me
./a.out
I then tried to make another .c
file that runs the script then launch the first a.out
as I thought that it was a timing issue the first time without success either...
How can I get it to work within a single a.out
or is that even possible?
c shell trap
marked as duplicate by Antti Haapala
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 29 '18 at 12:05
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Catch Ctrl-C in C
9 answers
I'd like to run a trap '' 2
command from a C program to prevent ctrl-c
when the a.out
is run.
#define TRAP "trap '' 2"
int main()
{
system(TRAP);
...
}
I can get it to work from a .sh
file that also runs the program but I'd like everything to be in one .c
file.
trap '' 2
cd /Users/me
./a.out
I then tried to make another .c
file that runs the script then launch the first a.out
as I thought that it was a timing issue the first time without success either...
How can I get it to work within a single a.out
or is that even possible?
c shell trap
marked as duplicate by Antti Haapala
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 29 '18 at 12:05
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
3
Thetrap
command is built into the shell itself, and only affects the currently running shell, and no other process. If you want to preventCtrl-C
from breaking your program (usually a bad idea) then look into signals andSIGBREAK
.
– Some programmer dude
Dec 29 '18 at 10:49
add a comment |
This question already has an answer here:
Catch Ctrl-C in C
9 answers
I'd like to run a trap '' 2
command from a C program to prevent ctrl-c
when the a.out
is run.
#define TRAP "trap '' 2"
int main()
{
system(TRAP);
...
}
I can get it to work from a .sh
file that also runs the program but I'd like everything to be in one .c
file.
trap '' 2
cd /Users/me
./a.out
I then tried to make another .c
file that runs the script then launch the first a.out
as I thought that it was a timing issue the first time without success either...
How can I get it to work within a single a.out
or is that even possible?
c shell trap
This question already has an answer here:
Catch Ctrl-C in C
9 answers
I'd like to run a trap '' 2
command from a C program to prevent ctrl-c
when the a.out
is run.
#define TRAP "trap '' 2"
int main()
{
system(TRAP);
...
}
I can get it to work from a .sh
file that also runs the program but I'd like everything to be in one .c
file.
trap '' 2
cd /Users/me
./a.out
I then tried to make another .c
file that runs the script then launch the first a.out
as I thought that it was a timing issue the first time without success either...
How can I get it to work within a single a.out
or is that even possible?
This question already has an answer here:
Catch Ctrl-C in C
9 answers
c shell trap
c shell trap
asked Dec 29 '18 at 10:44
Wizzardzz Wizzardzz
353215
353215
marked as duplicate by Antti Haapala
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 29 '18 at 12:05
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Antti Haapala
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 29 '18 at 12:05
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
3
Thetrap
command is built into the shell itself, and only affects the currently running shell, and no other process. If you want to preventCtrl-C
from breaking your program (usually a bad idea) then look into signals andSIGBREAK
.
– Some programmer dude
Dec 29 '18 at 10:49
add a comment |
3
Thetrap
command is built into the shell itself, and only affects the currently running shell, and no other process. If you want to preventCtrl-C
from breaking your program (usually a bad idea) then look into signals andSIGBREAK
.
– Some programmer dude
Dec 29 '18 at 10:49
3
3
The
trap
command is built into the shell itself, and only affects the currently running shell, and no other process. If you want to prevent Ctrl-C
from breaking your program (usually a bad idea) then look into signals and SIGBREAK
.– Some programmer dude
Dec 29 '18 at 10:49
The
trap
command is built into the shell itself, and only affects the currently running shell, and no other process. If you want to prevent Ctrl-C
from breaking your program (usually a bad idea) then look into signals and SIGBREAK
.– Some programmer dude
Dec 29 '18 at 10:49
add a comment |
1 Answer
1
active
oldest
votes
trap '' INT
ignores SIGINT
. Ignore dispositions are inherited to child processes, so:
trap '' 2
cd /Users/me
./a.out
ignores SIGINT
for what follows, but it can't work up the process hierarchy.
Fortunately it's not super difficult to ignore SIGINT
from C.
#include <signal.h>
int main()
{
//....
signal(SIGINT,SIG_IGN); // `trap '' INT` in C
//^should never fail unless the args are buggy
//...
}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
trap '' INT
ignores SIGINT
. Ignore dispositions are inherited to child processes, so:
trap '' 2
cd /Users/me
./a.out
ignores SIGINT
for what follows, but it can't work up the process hierarchy.
Fortunately it's not super difficult to ignore SIGINT
from C.
#include <signal.h>
int main()
{
//....
signal(SIGINT,SIG_IGN); // `trap '' INT` in C
//^should never fail unless the args are buggy
//...
}
add a comment |
trap '' INT
ignores SIGINT
. Ignore dispositions are inherited to child processes, so:
trap '' 2
cd /Users/me
./a.out
ignores SIGINT
for what follows, but it can't work up the process hierarchy.
Fortunately it's not super difficult to ignore SIGINT
from C.
#include <signal.h>
int main()
{
//....
signal(SIGINT,SIG_IGN); // `trap '' INT` in C
//^should never fail unless the args are buggy
//...
}
add a comment |
trap '' INT
ignores SIGINT
. Ignore dispositions are inherited to child processes, so:
trap '' 2
cd /Users/me
./a.out
ignores SIGINT
for what follows, but it can't work up the process hierarchy.
Fortunately it's not super difficult to ignore SIGINT
from C.
#include <signal.h>
int main()
{
//....
signal(SIGINT,SIG_IGN); // `trap '' INT` in C
//^should never fail unless the args are buggy
//...
}
trap '' INT
ignores SIGINT
. Ignore dispositions are inherited to child processes, so:
trap '' 2
cd /Users/me
./a.out
ignores SIGINT
for what follows, but it can't work up the process hierarchy.
Fortunately it's not super difficult to ignore SIGINT
from C.
#include <signal.h>
int main()
{
//....
signal(SIGINT,SIG_IGN); // `trap '' INT` in C
//^should never fail unless the args are buggy
//...
}
answered Dec 29 '18 at 10:55
PSkocikPSkocik
32.6k64870
32.6k64870
add a comment |
add a comment |
3
The
trap
command is built into the shell itself, and only affects the currently running shell, and no other process. If you want to preventCtrl-C
from breaking your program (usually a bad idea) then look into signals andSIGBREAK
.– Some programmer dude
Dec 29 '18 at 10:49