Preventing <Ctrl>+C possible?

General FreeBASIC programming questions.
Post Reply
skystrick
Posts: 104
Joined: May 19, 2013 23:25
Location: Florida

Preventing <Ctrl>+C possible?

Post by skystrick »

Is there any way to disable <Ctrl>+C, <Ctrl>+Z, and <Ctrl>+Break in a FreeBASIC program? As in, prevent users from being able to quit the program?

If it matters I am running Linux.
Trinity
Posts: 214
Joined: Sep 16, 2017 17:07

Re: Preventing <Ctrl>+C possible?

Post by Trinity »

Perhaps these threads will be of help :
viewtopic.php?t=6669
https://freebasic.net/forum/viewtopic.php?t=10199
Also , not knowing anything in particular neither on subject nor on Linux then I do not know if this MS article could possibly be of any help )?= :
https://support.microsoft.com/en-us/hel ... d-keyboard
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Preventing <Ctrl>+C possible?

Post by caseih »

EDIT: bad, broken code... please refer to fxm's example.

Give you an idea anyway. Unfortunately the C header files for signal handling have not been translated, so you'll have to provide the relevant parts yourself. See fxm's example code.
Last edited by caseih on Oct 14, 2017 14:19, edited 1 time in total.
fxm
Moderator
Posts: 12131
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Preventing <Ctrl>+C possible?

Post by fxm »

Warnings above fixed:

Code: Select all

#define SIGINT 2

type sigfuncptr as sub(byval signal_number as long)

'posix call
declare function signal cdecl alias "signal" (byval signal as long, byval sigfunc as sigfuncptr) as sigfuncptr

sub sig_handler (byval signo as long)
   if signo = SIGINT then
      print "received SIGINT!"
   end if
end sub

if signal (SIGINT, @sig_handler) = 0 then
   print "Can't catch SIGINT."
end if

dim k as string
while 1
   k = inkey()
   if k <> "" then end
   sleep 1
wend
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Preventing <Ctrl>+C possible?

Post by D.J.Peters »

The user of your App can kill it via taskmanager/processviewer or kill command ...
so what are the sense to disable key's in your App ?

Joshy
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Preventing <Ctrl>+C possible?

Post by caseih »

It's very common to trap SIGINT in unix programs, especially command-line ones. Trapping Ctrl-C allows you to run a proper shutdown when a user Ctrl-C's the program to quit (again, this is common in command-line programs). Actually it's common to catch SIGHUP, SIGTERM, and SIGINT. A normal kill is SIGTERM.

Thanks for the correct example, dkl. I've been doing too much C++ lately. My code was very wrong!
sancho3
Posts: 358
Joined: Sep 30, 2017 3:22

Re: Preventing <Ctrl>+C possible?

Post by sancho3 »

Thanks for the correct example, dkl
You better rub your eyes and look again.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Preventing <Ctrl>+C possible?

Post by caseih »

Ha. yeah. Sorry, fxm!
Post Reply