LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   bash script help - "screen" (https://www.linuxquestions.org/questions/linux-general-1/bash-script-help-screen-346191/)

Henster 07-24-2005 06:02 AM

bash script help - "screen"
 
Hi there,

Ive written this bash function:

Code:

function s {
    SciTe $1 &
}

SciTe is a text editor. This script works and I can type

s foo.txt

to edit my text.

But, if I close the terminal I started the editor from it closes. I heard from somewhere that "screen" is the command to use to detach the process from the terminal but I cant get it working with my script.

Can anyone help?

Thanks
H

heema 07-24-2005 06:11 AM

try :

s foo.txt &

Henster 07-24-2005 08:27 AM

Yes, that works..... but why?

I'd backgrounded the process in the script?

So can I include that second & in my script?

Thanks
h

heema 07-24-2005 08:36 AM

the "&" sign tell the process to run in the background

Code:

Run a command in the background

        command &

Put an active command into the background

        First break with control Z, then
       
        bg

List all the jobs you have running

        jobs

Bring a job back to the forground

        fg

Stop a background job

        kill

Suspend a backgroud job

        stop


RomanG 07-25-2005 05:00 AM

Sometimes if your programm is very interactive :) and do not want to work in background
you may use 'screen' command.
Well... Every programm running on your system has a state. You can see it in 8'th column in 'ps aux' command. Running programm has state 'S' or 'R'. When you terminate programm by pressing 'Ctrl+z' or running it with '&' some of them go into 'T' state. But there is a way to make programm work even if you logout from system.
Try to do like this:
Code:

...
root    14552  0.0  0.2  2476  1092 pts/0    S    22:46  0:00 su -
root    14553  0.0  0.5  3644  2592 pts/0    S    22:46  0:00 -bash
root    14758  0.0  0.2  2644  1312 ?        Ss  22:59  0:00 SCREEN -d -m top
root    14759  0.0  0.2  1972  1028 pts/1    Ss+  22:59  0:00 top
root    14793  0.0  0.1  2548  824 pts/0    R+  23:01  0:00 ps aux

Now you can logout from your system but 'top' will still be runnind.
Notice that it runs on an another terminal (do you see pts/0 and pts/1?)!!!
Also look at 'pstree' command output:
Code:

init─┬
...
    ├─screen───top
    ├─sshd───sshd───sshd───bash───su───bash───pstree
...

What do you think of it?
Now login again and do:
Code:

[root@squirrel ~]# screen -R
Then press 'q' and exit this virtual terminal with 'exit' - you will return into your normal shell now.
What is this for? I often use it in my normal work: just work in screen's virtual terminal, then deattach from it and exit shell with leaving my prog working... Sometimes use in scripts.


All times are GMT -5. The time now is 02:38 PM.