Avatar of Joe Rud
Joe RudFlag for United States of America

asked on 

Programmatically simulate a Ctrl+C

I'm working on a program written in C - running on Unix/Linux.  I need a way to send the equivalent of the user entering a Ctrl+C keystroke at the terminal.
CProgramming Languages-Other

Avatar of undefined
Last Comment
Joe Rud
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

... and to send it to yourself

#include <sys/types.h>
#include <unistd.h>
#include <signal.h>

kill(getpid(), SIGINT);

That's basically the same as "raise()":

#include <signal.h>

raise(SIGINT);
Avatar of Joe Rud
Joe Rud
Flag of United States of America image

ASKER

Thanks.  Works perfectly
C
C

C is a general-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations. By design, C provides constructs that map efficiently to typical machine instructions, so it has found lasting use in applications that had formerly been coded in assembly language, including operating systems as well as various application software for computers ranging from supercomputers to embedded systems. It is distinct from C++ (which has its roots in C) and C#, and many later languages have borrowed directly or indirectly from C.

23K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo