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 :)
Related
In CentOS7.2, when I launch gedit (/usr/bin/gedit the version is 3.14.3)
$ gedit hoge.txt
then the prompt returns immediately.
I am pretty new for UNIX world but where does the process go?
When I already have opened gedit, it looks gedit try opening a new tab in the existing window. That is why I cannot see the process by
$ ps (without x)
if the existing gedit is invoked in another shell.
I kind answered myself, but I want to ask how can it be done?
gedit deals with many technical process under the OS?
I realized
firefox
also looks similar.
In my case, gedit don't go to background when launched from terminal, but firefox does. So if I want to know what happens with firefox, I will run
ps -fu `whoami` | grep firefox
And look for its PID in the output (18235 in that case):
me 18235 1900 20 jul28 ? 22:58:52 /usr/lib/firefox/firefox
Then I will run pstree like this:
pstree -Ahps 18235
And the output of pstree will show me the processes tree for launched firefox
init(1)---lightdm(1272)---lightdm(1893)---init(1900)---firefox(18235)-+-plugin-containe(8990)-+-{plugin-containe}(8992)
| |-{plugin-containe}(8993)
| `-{plugin-containe}(8994)
|-{firefox}(18242)
|-{firefox}(18243)
|-{firefox}(18245)
|-{firefox}(18246)
|-{firefox}(18247)
It loks like firefox(18235) is attached to parent init(1900) who's attached to lightdm(1893), etc.
Let me explain better. What is gonna happen if I run a command in Linux and before it's done and you could enter another command I close the terminal. Would it still do the command or not?
Generally, you must expect that closing your terminal will hangup your command. But fear not! Linux has a solution for that too!
To ensure that your command completes, use the nohup argument first. Simply place it before whatever you are trying to do:
nohup ./some_program
nohup ./do_a_thing -frx -file input_file.txt
nohup grep "something" giant_list_of_files/* > temp_file.txt
The nohup command stands for "no hangup" and it will ensure that the command you execute continues to run, even if you close your terminal.
It depends on the process and your environment (job control shell options, VNC, etc). But typically, no. The process will get a "hangup" signal (message) from the operating system, and upon receiving that, will quit.
The nohup command, for example, arranges for processes to ignore the hangup signal from the OS. There are many ways to achieve the same result.
I would say it will abort att the status you are in just before the session close.
If you want to be sure to complete the job, you will need to use the nohup command.
http://en.wikipedia.org/wiki/Nohup
Read about nohups and daemons (-d)...
A good link is [link]What's the difference between nohup and a daemon?
Worth look at screen command, Screen command offers the ability to detach a long running process (or program, or shell-script) from a session and then attach it back at a later time.
Is there a command line utility that I can use for executing X based applications that will detach my applications from the terminal so they aren't closed if the terminal is closed?
I guess such a app could be called something like gnome-run if it existed.
I have tried dtach, but it seems that you have to provide a socket file which is a bit clunky to type. I have also tried nohup, but found that also to be a bit clunky to type by the time std out and err are redirected to /dev/null.
I guess I'm looking for a simple program that will do something similar to this:
#!/bin/bash
nohup $1 > /dev/null 2>&1 &
Yes, there is a way to do it: first you need to run your GUI app and send it to background, then you (probably) want to detach it from Bash task management. For example if I wanted to run gedit this way:
gedit &
disown %1
After that you can close your terminal window and gedit will not be killed. Enjoy!
You already wrote your program, it is called a shell script and you give it the name you like and put it somewhere. Then you either add that directory to your $PATH or in your bashrc you set:
alias gnome-run=<path>/my-awesome-script.sh
Why waste earth's resources on a program?
If you want to run an application (say, gedit) as if it was run from the GUI, use:
xdg-open /usr/share/applications/gedit.desktop
See this answer on superuser.
I have written a Fortran program (let's call it program.exe) with does some simulation for me. Via ssh I'm logging ino some far away computers to start runs there whose results I collect after a few days. To be up-to-date how the program proceeds I want to write the shell output into a text file output.txt also (since I can't be logged in the far away computers all the time). The command should be something like
nohup program.exe | tee output.txt > /dev/null &
This enables me to have a look at output.txt to see the current status even though the program hasn't ended its run yet. The above command works fine on my local machine. I tried first with the command '>' but here the problem was that nothing was written into the text file until the whole program had finish (maybe related to the pipe buffer?). So I used the workaround with 'tee'.
The problem is now that when I log into the computer via ssh (ssh -X user#machine), execute the above command and look at output.txt with the VI editor nothing appears until the program has finished. If I omit the 'nohup' and '&' I will not even get any shell output until it has finished. My thought was that it might have to do something with data being buffered by ssh but I'm rather a Linux newbie. For any ideas or workaround I would be very grateful!
I would use screen utility http://www.oreillynet.com/linux/cmd/cmd.csp?path=s/screen instead of nohup. Thus I would be able to set my program to detached state (^A^D) reconnect to the host, retrieve my screen session (screen -r)
and monitor my output as if I never logged out.
I have an application which spawns several processes. Is it possible to redirect the output of the children to another hidden terminal so that it does not mix with the parent output and give the ability to the end user to unhide the terminal when needed?
Thanks.
The quick and dirty way to do this is to redirect the child process' output to a (temporary) file.
A terminal tracking that file can then be started using a command like
xterm -e tail -f /tmp/child1.out
This terminal can be closed and opened when needed.
If you'd rather not store the output in a file, you can use a fifo (see mkfifo(1)), but then you lose the ability to see the past output, since a fifo doesn't store data.
from your terminal, run:
touch proc1.log
xterm -e tail -f proc1.log
topuch proc2.log
xterm -e tail -f proc2.log
/run/proc/1.sh >> proc1.log
/run/proc/2.sh >> proc2.log
now you have 2 terminals following the output of the spawned processes
Screen can do this. You can start a detached screen with the new program.
Something like:
screen -d -m -S my-emacs-session emacs foo.c