linux screen -r doesn't work - linux

I am trying to re-attach different screen sessions that I have open. As usual, I try:
screen -r [screen name]
This normally works, but now it keeps hanging the terminal. Ctrl+c doesn't help, and I end up having to close the terminal. Other screen functions (screen -ls, screen -S [new screen name]) work fine.
One of the screens has a process running in it. I can see from the existence of generated output files that the process is still running. I just can't access the screen itself.
I tried creating a new screen, detaching it, and re-attaching it - this works fine. I can access new screens, but not the ones that were open before this problem popped up.

You should do kill the screens which has problem. Try,
screen -X -S <screenname> kill
If it's not working, you should kill these processes by yourself. First you should find which are those have an issue. By typing;
ps aux
Then find PID number of process which you want to kill. And type;
kill -9 <pidnumber>
And check it works fine :)
Regards,
Evren

Related

How does screen command works in Linux

If a do screen in linux, and then ssh into some other machine, run a job there, detach from screen and disconnect the terminal. If i open the terminal again i can go that session and job is still running. I just want to know how internally this screen is working?
Detach does exactly what literally means.
It detaches the screen process from it's parent.
It means that his parent (your ssh session) will not inform his dependent/child process about its termination.
For more info this links could be useful:
https://en.wikipedia.org/wiki/Nohup
https://unix.stackexchange.com/questions/3886/difference-between-nohup-disown-and
After ssh and successful login use screen -S screen_name to generate screen, then new tab will open. Run your program and you may close it. To see your program running use: screen -r screen_name.

Close google chrome open in app mode via command line

In my python script I am opening chrome in app mode by this command:
google-chrome --app=http://stackoverflow.com
Now I want to be able to close only this running chrome application (I mean if there is another chrome windows with diffrent tabs I don't want to close that, only this that i run). Is this possible and how?
I am using linux.
EDIT:
As far i manage to do something like this:
import subprocess
proc = subprocess.Popen(['google-chrome',
'--user-data-dir=/home/chrome-user', 'http://google.pl'])
# do something
proc.terminate()
And when I call this python script from command line everything is ok. My problem starts when I am running this as a linux service (under /etc/init). I logged and everything is ok except that google chrome seems to not be able to create window or something? I mean there is no error but google chrome window doesn't shows at all.
EDIT 2:
Definitely it is a problem with startup. When i run this on startup:
mate-terminal -e "python3
/path/to/script/script.py"
Everything works fine except that terminal windows is shown. So this somehow solves my problem but if anyone will have got any sugestion what can i do i would highly apreciate it.
as far as I know chrome creates a new process for each tab, killing the process therefore would work. you can kill the process by PID and the PID can be retrieved like this right after starting the process: (in bash) echo $!
Ok so after a long time I come with answer. In linux mint you need to add this to startup programs:
mate-terminal -e "python3 /path/to/script/script.py"
and if you want to run script as root user, this is solution for it (it's very ugly, but works):
mate-terminal -e "bash -c 'echo pass | sudo -S python3 /path/to/script/script.py;$SHELL'"

How to move a process which ppid is '1' to foreground on CentOS 6.5?

I wrote a c++ program which need lots of time to calculate, so I put it to background and set its ppid to '1'. Then I can logout and keep it running on the server.
Now I'm login to the server again, from 'top' I can see it's still running, I want to move the process to foreground then check the current output but don't know how to do it, I'm still a rookie to linux, really need your help.
The output is using '\r' to keep refresh in one line, show the rate of progress.
I tried 'jobs' and find nothing, out put is empty.
All you have to do it, run it with nohup
nohup ./a.out > your_log_file.log &
whenever you login back to server just do tail -f your_log_file.log

tmux: hangs and do not load, and do not respond to any option command

I have installed tmux from source on my localspace in Fedora. It was working nicely so far. But suddenly can not run it anymore, when run tmux, it just halts. Tried different command options like ls-sessions, none works. Killed all the processes of my user, deleted all the files of tmux and libevnet, and reinstalled them again from scratch. Still same, and tmux command in terminal just freezes without any actual error.
I had faced this problem for a long time and after a bit of searching I figured out that this was being caused because I accidently hit Ctrl+S (Ctrl+A+S is my shortcut for switching panes), and this turns off flow control in terminals and stops the terminal from accepting input. It can be reenabled by pressing Ctrl+Q.
Source: https://superuser.com/a/553349/137226
Had a similar issue, where I had a tmux session with two buffers. I didn't see anything I typed, but when I switched between buffers what I had typed previously would appear onscreen. stty sane didn't work.
I detached Ctrl-b+d, and noticed that there was still a client attached when I looked at tmux list-clients. tmux detach-client removed it, and then I could reattach and the everything worked again.
If it is ok to lose your sessions, try deleting the tmux-NNNNNNN directory, where NNNNNNN is a number, under your /tmp directory. According to the tmux manual, if the TMPDIR environment variable is set, the tmux-NNNNNNN will be put in the TMPDIR.
tmux stores the server socket in a directory under /tmp (or TMPDIR if set);
This solved my problem of not being able to run tmux commands that are related to sessions. I also tried the following, but they did not work:
killall -9 tmux
reinstall tmux
restart shell session
I could not easily restart the operating system, because it's a shared server managed by others.
tmux was halting right after I started it. Ctrl-Q and Ctrl-C didn't do anything.
Fixed with
killall -9 tmux
(May be a different problem, but this question showed up in Google.)
I had the same issue. The cause is that the tmux buffer is full, and it also may happens cause of multi clients to the tmux session.
To solve it you need to detach all the clients from the session, and reattach it.
The best way I found to solve it is to add to the ~/.bashrc file this functions:
check_params() {
if [[ $1 < $2 ]]; then
echo -e "Usage:\n${3}"
ok=0
else
ok=1
fi
}
# detach all the clients from this session, and attach to it.
reattach_client() {
check_params $# 1 "reattach_client <tmux_session_name>"
if [[ $ok == 1 ]]; then
tmux list-client | grep $1 | awk '{split($1, s, ":"); print s[1]}' | xargs tmux detach-client -t | true
tmux attach -t $1
fi
}
then run source ~/.bashrc to make these changes in the terminal.
Now to attach the session type:
reattach_client <session_name>
solved my issue.
Thanks to Alex Zelichenko for help me with this!
You should be able to narrow down your problem a bit with a few of these tests:
Give it a shot from outside X11: Ctrl+Alt+F2 (or use ssh from another computer)
Test if other terminal emulators work: script and screen
Try another complicated terminal application: htop and mc
Reset your TTY settings: stty sane
Check that your terminal identified: echo $TERM (it should be something like "xterm" or "linux")
Make that your terminal capabilities file exists: ls -lh /usr/share/terminfo/*/$TERM
Thanks.
I found the problem. The tmux process were in D state, and I had no choice but to reboot the system.
The problem came from kerberos ticket expiring after a while. And find a scripts that solves this problem:
https://iain.cx/src/ktmux/
A less drastic action (to try before killing the tmux process) is to ssh into the machine and run the following command.
kill -CONT `pidof tmux`
Source: https://github.com/tmux/tmux/issues/507#issuecomment-271502093
This happened to me because I accidentally tried to create two parallel tmux sessions with the same name.
What worked for me was to enter htop, checking pid's of the two running commands that created the sessions, and killing both by using kill -9 pid1 and kill -9 pid2

See GNOME Terminal output in virtual console

I've got a program running in a GNOME Terminal, but the screensaver is acting up and won't let me back in with my password. While waiting for a fix for the gnome-screensaver bug, is there some way to see the output (or even take over the process) in a virtual console (Ctrl-Alt-F1) without being able to interact with the GNOME Terminal?
Clarification: The original issue was the screensaver, but the question I'd like answered is how to see the output from a process running in another terminal, after starting the process without any logging to file. I'm guessing it should be possible to set the output device of a process from a different shell? Or is it possible to put a process in another shell into background mode, and get it into the foreground in the current shell? Or even ask GNOME Terminal to redirect or copy the output?
I've had luck in the past killing the screensaver from a virtual console, unlocking X session.
# Get the pid (xscreensaver, gnome-screensaver, etc.)
ps -f -u $(whoami) | grep screensaver
kill -9 12345 # Replace 12345 with the real pid
EDIT: Seems like this has been thought of, and you should use one of these commands, depending on which screensaver program you use:
xscreensaver-command -exit
gnome-screensaver-comand --exit
See the man page for those commands for more details.
Usual way is to pipe the output to a file, like program > program.log
Do tail -f program.log in another tab of Gnome console, and the same in the non-X console.
Alternatively, use tee to duplicate the output in the same console: program | tee program.log
ssh in to the box. kill the screensaver. su to become root and kill -9 if it's really acting up.
Usually Gnome-Terminal displays the output of one vty out of /dev. So just connect your console to that vty.
Launch program with screen.
Open another terminal, launch screen -x and you have two terminals acting like one. Try it, it's fun :)

Resources