LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-24-2005, 06:02 AM   #1
Henster
Member
 
Registered: Jul 2004
Posts: 45

Rep: Reputation: 15
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
 
Old 07-24-2005, 06:11 AM   #2
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 47
try :

s foo.txt &
 
Old 07-24-2005, 08:27 AM   #3
Henster
Member
 
Registered: Jul 2004
Posts: 45

Original Poster
Rep: Reputation: 15
Yes, that works..... but why?

I'd backgrounded the process in the script?

So can I include that second & in my script?

Thanks
h

Last edited by Henster; 07-24-2005 at 08:28 AM.
 
Old 07-24-2005, 08:36 AM   #4
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 47
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
 
Old 07-25-2005, 05:00 AM   #5
RomanG
Member
 
Registered: Jan 2005
Location: Russia, Kazan
Distribution: Mandrake 10.2, RedHat sometimes..
Posts: 110

Rep: Reputation: 15
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
How to write a bash script to replace all "KH" to "K" in file ABC??? cqmyg5 Slackware 4 07-24-2007 09:00 AM
searching "TIC TAC TOE" bash script LV-chronos Linux - Newbie 5 05-29-2005 02:20 PM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 02:32 PM
Bash Script: Problem running variable command containing "" Paasan Programming 2 01-21-2004 01:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration