Amiga.org
Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: kas1e on November 26, 2004, 12:52:49 PM
-
hi all. i have little question about ctrl+c and 'break' handling. sas/c compiler used. so:
main()
{
while(1)
{
if (CheckSignal(SIGBREAKF_CTRL_C))
{exit(0);};
}
}
if i press ctrl+c in cli, all ok, and 'status' command said
that not load program. but if i kill my programm by 'break'
command, 'status' said: Proccess 1: No command loaded. but anyway process present. how i must handler 'break' in my whyle loop for good killing by 'break' ?
-
I hope your real code dosn't busy-wait like the fragment above.
Well, which AmigaOS and which compiler do you use ?
What does your CheckSignal function do ?
Did you free all AmigaOS resources before you exit() ? Exit() only frees ANSI C resources (malloc and similar).
How did you start the program ?
E.g. if you opened two Shell windows, one for your programm and another one for the Break command, after the break your program returns to the Shell, but the Shell window is still there, so the "no command loaded" is correct. The process only disappears if you end the Shell.
To strip down your code fragment to the essential and to make it system-friendly, it should look like this:
#include <proto/exec.h>
#include <dos/dos.h>
int main (void)
{
Wait (SIGBREAKF_CTRL_C);
return (0);
}
Bye,
Thomas
-
>I hope your real code dosn't busy-wait like the fragment above.
i recv() from socket in while. and test on ctrl+c:
while(recv(.....))
{
.........
ctrl+c();
.........
}
>Well, which AmigaOS and which compiler do you use ?
3.9bb2, sasc/vbcc.
>What does your CheckSignal function do ?
it's not my, it's from dos.library():
NAME
CheckSignal -- Checks for break signals (V36)
FUNCTION
This function checks to see if any signals specified in the mask have been set and if so, returns them. Otherwise it returns FALSE.All signals specified in mask will be cleared.
i don't now, who preferred Wait() or CheckSignal().. btw, thnx for answer, it was 2 open shells :) so, all is ok.
btw, maybe you know what i can redirect all 'cli' output to
file or memory ? i mean:
char buf[500];
SystemTags("newcli",???); // cli start, but output redirect
// to buf[];
?
-
i recv() from socket in while. and test on ctrl+c:
while(recv(.....))
bsdsocket.library can do CTRL-C checking for you. See SocketBaseTagList autodoc about SBTC_BREAKMASK.
what i can redirect all 'cli' output to
file or memory ? i mean:
char buf[500];
SystemTags("newcli",???); // cli start, but output redirect
// to buf[];
You can't redirect to memory, you need to use temporary file and SYS_Output tag. The output file can use PIPE:, however.
-
i can create tmp file in memory ? i mean, i not want create file on hdd. (in ram: too, becouse name of file will be anyway). maybe here is some flag for 'memory file' ?
-
No, you cannot create a file in memory. RAM: or PIPE: are the only possibilities. You can use the task pointer to make the file name unique.
Something like this:
char tempfilename[30];
BPTR tempfile;
sprintf (tempfilename,"t:tempfile%x",FindTask(NULL));
tempfile = Open(tempfilename,MODE_NEWFILE);
Execute ("command",NULL,tempfile);
Close (tempfile);
Open (tempfile,MODE_OLDFILE);
bytes_read = Read (tempfile,buffer,buffersize);
Close (tempfile);
Delete (tempfilename);
Bye,
Thomas