How to open program from command line in the background (below windows already opened)? - background

I have small python script that opens few dozens of instances of xterm and closes most of them after few seconds.
Using command like this:
for i in range (80)
os.system("xterm -e echo example &")
allow xterm to be opened 80 times but windows are popping in front of the work space - so using any other program is impossible for minute or so.
Is there any way of opening those windows in the background?

Related

Get DISPLAY environment variable from a local terminal to the Visual Studio Code terminal through SSH

I'm using VScode with Windows Subsystem for Linux (WSL) and working through an SSH connection.
Unfortunately, the Remote - SSH extension by Microsoft doesn't enable X11 forwarding (#267), and thus an extension such as Remote X11 has been created.
Sadly, this extension doesn't work for me as I'm working through a jump host/gateway, and therefore have to manually change the DISPLAY variable in the VScode terminal to the DISPLAY variable found in another terminal that is used for displaying stuff.
I guess it is possible to get the DISPLAY variable by running tr '\0' '\n' < /proc/<pid>/environ | grep DISPLAY(Environment variables of a running process on Unix?), with the <pid> being run from the local terminal, and now it's just a problem of automating the search for this process.
So i guess the stuff I'm asking for, is a way to:
Get the pid from a process on a local terminal
Get the DISPLAY variable from this process
Set the DISPLAY variable in every newly opened terminal in VScode (perhaps running step 2 in the workspace-settings.json)
PS. I'm using the VcXsrv X Server

ConEmu stopped working with Bash on Windows

I have been using ConEmu for some time to run 'bash for windows', but all of the sudden it stopped working. When I launch a bash tab it now says:
ConEmuC: Root process was alive less than 10 sec, ExitCode=0.
Press Enter or Esc to close console...
I think this means that it launched something, but the shell closed quickly. I haven't changed anything that I can recall with the system, it just started doing that.
Windows version: 10 (build 15063)
ConEmu version: 180626 preview
No windows updates were done recently.
If I launch 'Bash on Ubuntu on Windows' from the start bar, it works fine (but I prefer using conemu as a terminal). Also, I can launch a cmd tab in conemu, then type bash and the bash shell will start. Unfortunately, launching bash in this way results in a lack of mouse support, and strange arrow key behavior.
I am at a bit of a loss. It worked perfectly previously... then it just stopped. Any help on how to debug or fix this would be appreciated.
If anybody finds this with a similar problem, my solution was to make a new task in ConEmu, with the command:
%windir%\system32\bash -l -i -cur_console:p5
The key is the -cur_console:p5, which sets the pty type as:
p[N] - pty modes, N - bitmask: 1 - XTermKeys, 2 - BrPaste, 4 - AppCursorKeys; default is 5 (1+4)
For some reason, setting p5 is necessary for me, despite it being listed as the default. Still not sure what changed, but at least it is working now.
I have the same problem but (for what it's worth) found that when it happens (varying between intermittent and incessant) restarting my machine fixes the issue every time.

Can I retrieve the output of a program, that is running in another terminal and/or run by root as e.g a cronjob?

Just for the sake of the question, say I open a terminal an log into my Linux computer. I run a program that keeps outputting information on my screen, looping. I close the terminal window, and the program shuts down.
I set up a cronjob or a startup script that launches the same program as in example 1. The program is looping now, run as root.
I open a terminal, and log into my computer through SSH. Can I make a Bash script that retrieves the output of said program, even if it's running somewhere in the background? I mean, is the program "virtually" outputting information (as in example 1)?
The program closes stdout and stderr when it exits. Looping it as you describe will just cause it to start and exit continuously. You could look at redirecting stdout and stderr.

tmux session stops updating screen randomly

I use tmux 1.6-2 on a Debian 7.6 (wheezy).
I open a new session and start a long running script that gives updates in form of a progress bar and an activity indicator (spinning bar: /-\|/ ).
When I detach and reattach everything is still fine. But after some random time when I reattach the screen content is stuck. No spinning bar, no progress. I looked into the following:
I can see in top that the process is still running
I can successfully enter tmux commands (like new window, detach, etc.)
I can kill the script with Ctrl-C, but the tmux screen doesn't change
Ctrl-S and Ctrl-Q (like suggested in other threads) doesn't help
Any help is very much appreciated.
I managed to unfreeze my tmux session by running choose-client command from tmux's command line <prefix> :
where prefix is C-b by default
I found the solution in the bug report (by Taisuke Yamada).

beep remote tmux when job is done

im a linux fan.
A few days ago i found tmux very useful.
Now im using it all day.
I run tmux on a remote shell and working there. On my local pc only one terminal working.
And i found interesting thing:
my mutt program is beeping when new mail arrives. And tmux is transferring this beep to my local PC, is there a way to run similar beep by any shell command ?
I want to use it for some command finishing sign.
I wrote a little script called beep.sh that I use for things like that:
#!/bin/bash
echo $'\a' > `/usr/bin/tty`