Welcome, Guest. Please login or register.

Author Topic: while & ctrl+c . 'break' signal.  (Read 2758 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline kas1eTopic starter

while & ctrl+c . 'break' signal.
« 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' ?
 

Offline Thomas

Re: while & ctrl+c . 'break' signal.
« Reply #1 on: November 26, 2004, 01:30:34 PM »

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

Offline kas1eTopic starter

Re: while & ctrl+c . 'break' signal.
« Reply #2 on: November 26, 2004, 06:30:11 PM »
>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[];

?
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: while & ctrl+c . 'break' signal.
« Reply #3 on: November 26, 2004, 06:54:34 PM »
Quote
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.

Quote
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.
 

Offline kas1eTopic starter

Re: while & ctrl+c . 'break' signal.
« Reply #4 on: November 26, 2004, 09:17:19 PM »
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' ?

 

Offline Thomas

Re: while & ctrl+c . 'break' signal.
« Reply #5 on: November 28, 2004, 12:05:26 PM »

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