Where is Jbrk for J on Linux? - j

On windows and Mac I could click the yellow 'Jbrk' icon to break a time-consuming computation running in my Jqt session. How to do that on linux?
I don't want to kill the session, as there could be some useful variables living in the current locale.

In a J linux install the jbrk shell script will interrupt your Jqt session. That is, in the J install folder .../bin/jbrk will signal a break to the Jqt session.

Related

Can I open a shell prompt from within NodeJS?

I'm in a NodeJS command-prompt session and I want to dip out to shell for a few commands and come back to my session with variables intact.
I remember doing this as a kid using "!" in another environment - can I do something like that in Node?
I just remembered about Ctrl-z / fg. Ctrl-z makes the Node session a background process and leaves me in the shell (and pauses it - if I wanted it to keep running something I could use the bg command). Then fg puts me back into the Node environment.
This is probably close enough to what I was thinking about.
I'm open to other options though!

Win 10: Cmd can bring windows to foreground, but any other terminal can't(even if elevated). Why is this so?

I'm using pygetwindow to bring a window to the foreground, via it's title. And it works flawlessly if I run my python script from cmd(and PowerShell). But if I run it from any other terminal, say Alacritty, instead of coming to the foreground, the mentioned window just starts flashing in the taskbar.
Why would this be so? I've configured Alacritty to use cmd.
Following is the relevant part of my code:
import pygetwindow
try:
window = pygetwindow.getWindowsWithTitle('foobar')[0]
window.activate()
except Exception as e:
#raise e
print("open foobar please")
exit(1)
And following is the relevant part of my alacritty config
# Shell
# You can set `shell.program` to the path of your favorite shell, e.g. `/bin/fish`.
# Entries in `shell.args` are passed unmodified as arguments to the shell.
# Default:
# - (macOS) /bin/bash --login
# - (Linux/BSD) user login shell
# - (Windows) powershell
shell:
program: cmd.exe
args:
- /s /k pushd C:\Users\interesting\bug\hunt\Repos
Thank You
Your program must comply with one of the following to be allowed to set the active window (which uses the API call SetForegroundWindow).
You may find using SendKeys to send system keystrokes like Ctrl+Tab will work for you, but you need to be able to predict your z-order.
The system restricts which processes can set the foreground window. A
process can set the foreground window only if one of the following
conditions is true:
•The process is the foreground process.
•The process was started by the foreground process.
•The process received the last input event.
•There is no foreground process.
•The process is being debugged.
•The foreground process is not a Modern Application or the Start
Screen.
•The foreground is not locked (see LockSetForegroundWindow).
•The foreground lock time-out has expired (see
SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo).
•No menus are active.
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setforegroundwindow
The purpose of these restrictions is solving a problem of programs stealing focus. So basically if the user clicks another window the user's choice wins.
When starting programs the program has two seconds to show a window. If the user clicks a another window before the program shows its' window within the two seconds then that program will still become the active window. If the program takes longer than 2 seconds and the user clicks away the user's window will be the active window.
Also see https://devblogs.microsoft.com/oldnewthing/20090220-00/?p=19083 for a discussion.

Move process to other TTY

Is it possible to move a process from one terminal to another in Linux? For example, if I have executed the "top" command via a gnome-terminal window, I want to move the output shown in the gnome-terminal window to a TTY terminal.
It's too late by the time you've already executed it, but if you recognise in advance that you might want to move it, you can use
screen top
to run top, and then detach from the running process with Ctrl-A and D. After that, you can run
screen -r
from any terminal on the same machine to reattach.
It's very powerful, and does a lot more than just that.

getting a program to return immediately at the command line so it's not tied to the shell that launched it

Some programs return immediately when launched from the command line, Firefox for example. Most utilities (and all the programs I've written) are tied to the shell that created them. If you control-c the command line, the program's dead.
What do you have to add to a program or a shell script to get the return-immediately behavior? I guess I'm asking two questions there, one for shell scripts and one for general, if they're different. I would be particularly interested to know if there's a way to get an executable jar to do it.
I'm almost embarrassed to ask that one but I can't find the answer myself.
Thanks!
start cmd
on Windows,
cmd &
on *nux
Here substitute
cmd = java -jar JarFile.jar
On *nux the fg and bg commands are your friends as well ...
You need to basically need to fork a process or create a new thread (or pretend to)
in *nux you can do this with an & after the command like this /long/script & or in windows you can create a BATCH file that executes your processes then exits (it does this naturally).
NOTE: there's no particularly good way to reference this process after you're forked it, basically only ps for the process list. if you want to be able to see what the process is doing, check out using screen (another linux command) that will start a session for you and let you "re-attach" to the screen.
to do this, install screen (sudo apt-get install screen or yum install screen). then type screen to create a new session (note, it will look like you didn't do anything). then, run your /long/command (without the &), then press CTRL + A + D (at the same time) to detach from it (it's still running!). then, when you want to re-attach, type screen -r.
Additionally, look for flags in any help message that allow you do this without using the above options (for instance in synergy you can say synergy --background)
A wrapper script consisting of nothing but:
your_prog_or_script &
Will launch the target and exit immediately. You can add nohup to the beginning of that line so it will continue running if the shell is exited.
For an executable program (as opposed to a shell script), on Linux/Unix use fork() and exec() and then exit the parent process, which will return to the shell. For details see the man pages, or some page like http://www.yolinux.com/TUTORIALS/ForkExecProcesses.html.

How do I make my cygwin .xinitrc wait for the X server to exit?

I'm using Cygwin's startx and want to customize my xinitrc so that I don't get any "magic" X programs on screen, i.e., programs that will cause the X server to terminate if I exit them. I don't want any X programs to start up on screen at all, actually; I just want to use the XWin menu, customized from my .XWinrc .
Ordinarily from a .xinitrc, I would make the last line run the window manager. Then I can exit X by exiting the window manager from its own provided interface.
In this case, though my window manager and my server are effectively the same process, because I am using the XWin server. I don't have a windows manager to execute. I am starting the server from my .xserverrc file:
exec XWin -multiwindow -clipboard -silent-dup-error
I can sleep at the end of my .xinitrc, in a loop:
while [ 1 -eq 1 ]
do
sleep 10
done
But that seems inelegant.
I can wait for a child process, either by starting it up as the last line in my .xinitrc, or by starting it up earlier in the background and waiting for it explicitly with "wait {PID}". But I can't wait for the XWin.exe process, because it is a parent process of my .xinitrc script, not a child process.
I can't start up XWin.exe at the end of .xinitrc; if I try, I get a different window manager apparently starting up, with XWin not in rootless mode, and then I get an immediate shutdown.
Is there a more elegant way to do this than sleeping in a loop? Is there a way to start XWin from my .xinitrc and wait on it? Is there a way to tell the .xinitrc shell script to simply wait and not exit, without sleeping, such that it will continue executing and do nothing until XWin.exe exits? Is there something I should be starting in the background as the last line of my .xinitrc, so as to give me a process to wait on without starting up an X program?
So, summarizing from Ben Bullock's answer, the answer to "How do I make .xinitrc do this?" is "Don't!" Never ask "How do I use X to do Y?" questions. :) Skip startx/.xinitrc entirely.

Resources