Guides/Interrupt

From J Wiki
Jump to navigation Jump to search

Jbreak - Interrupt Execution

If J is not responding you can signal it to interrupt execution. A J task can be signaled by another task called Jbreak. Jconsole is signaled by ctrl+c or Jbreak.

One signal stops execution at the start of the next sentence with an attention interrupt. Two signals stops execution in the middle of a sentence with a break. A signal when a program requests keyboard input (1!:1[1) stops execution with an input interrupt.

You can create a desktop shortcut that calls Jbreak, by running the appropriate file in the J bin subdirectory. On Windows, this is jbreak.bat, on OSX jbrk.command, and on Linux jbrk.

It is better to use a single signal to get an attention interrupt as the state of execution at the start of a line is clear. In a break it is not clear what has been executed and there is some chance of crash as it is difficult to ensure a clean state in all cases. Wait several seconds before getting impatient and giving the second signal.

Jbreak will also signals Jconsole, although it is usually easier to use ctrl+c.

Tech Details

The JE (J Engine) tests a byte in memory for a signal. This byte can be shared with another task with a mapped file. The other task signals J by writing to the mapped byte.

9!:47 sets the name of the break file that is the shared mapping of the byte. 9!:46 returns the name of the break file.

Profile uses break.ijs (open 'break') to set a default break file. JBreak runs Jconsole with sentence break'' to write to all default break files. If you are working with only 1 J task, or if only one task is running then this works fine. However, if you have a running production J task while you are using break with another J task you will break both tasks unless you take specific steps.

If you want a task to not be affected by default break signals then it should use setbreak from break.ijs to give the task a break file with a different suffix. For example:

   9!:46''
C:\Users\John\j807-user\jbreak\2748.default
   setbreak_j_ 'production'
C:\Users\John\j807-user\jbreak\2820.production
   9!:46''
C:\Users\John\j807-user\jbreak\2820.production

This task will not be affected by the default Jbreak. You can provide an argument to breaker.ijs to signal J tasks with a non default suffix.

Deleting Break Files

Usually the break file is deleted when J is closed. However, if J crashes for any reason, the break files may remain. It is safe to delete any such files in the break folder when J is not running.