Running a command in a new process?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running a command in a new process?
# 1  
Old 06-19-2011
Running a command in a new process?

I'm using GNU screen for an application that I'm making. I will try to explain:

This application opens 2 screen session, A and B. Screen session A has a script running in teh first window. I want to be able to switch from screen session A to screen session B, from the script running in session A (a convenience for the user)

The problem is: when ever I try to make screen B appear (screen -d -r B -- i've also tried screen -d A && screen -d -r B), it attaches as a child of screen session A (so now B is a subscreen of A) - where I'm actually intending to disconnect from session A, and show the user session B. I need to run these commands as if they were entered from outside of screen, but i'm not sure how to do that (somehow create a new process to run those commands in)

any ideas?


---------- Post updated at 06:31 AM ---------- Previous update was at 05:52 AM ----------

I realize that its hard to properly explain what it is I need.. I whipped up a quick example...
#create session A                                                               
screen -d -m -S A -t "SessionA-1" $HOME/                              
#and give it an extra tab..                                                      
screen -r A -X screen -t "SessionA-2"                                           
#give it a hardstatus line so we can see which session we're in                 
screen -r A -X hardstatus on                                                    
screen -r A -X hardstatus alwayslastline                                        
screen -r A -X hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%
{W}%n*%f%t%?(%u )%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'  
#create sessionB                                                                
screen -d -m -S B -t "SessionB-1"                                               
screen -r B -X screen -t "SessionB-2"                                           
#give it a hardstatus line so we can see which session we're in                 
screen -r B -X hardstatus on                                                    
screen -r B -X hardstatus alwayslastline                                        
screen -r B -X hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%
{W}%n*%f%t%?(%u )%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'         
# now show session A to the user                                                
screen -r A -p 0
echo " I'm going to show you session B in 10 seconds...."                       
sleep 10                                                                        
screen -r B && screen -d A

put those both in your home folder and run ./

What happens: After 10 seconds, screen B is opened within screen A

What I want to happen: After 10 seconds, screen A is disconnected, and screen B is then shown to the user (not as a child of screen A)

so I'm sure this line is the problem:
screen -r B && screen -d A
I need it to run as a new process outside of screen.... any thoughts?
# 2  
Old 06-22-2011
Originally Posted by jondecker76
so I'm sure this line is the problem:
screen -r B && screen -d A
I need it to run as a new process outside of screen.... any thoughts?
You're using 2 screen sessions when maybe you just want 2 screen windows inside of 1 session?

Either way your example did not work for me, but maybe you want to issue a

screen -S B -X detach

I'd assume you'd need this invoked from outside the screens to continue onward with an attach..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check if process is running if not then use command

Hello, Could someone do the following bash ubuntu script for me? I have 5 screen processes of bot: SCREEN -dmS Xbot_instance_1 php core.php -i 1 SCREEN -dmS Xbot_instance_2 php core.php -i 2 SCREEN -dmS Xbot_instance_3 php core.php -i 3 SCREEN -dmS Xbot_instance_4 php core.php -i 4 ... (2 Replies)
Discussion started by: kotch
2 Replies

2. Shell Programming and Scripting

Command to get exact tomcat process I am running ignoring other java process

Team, I have multiple batchjobs running in VM, if I do ps -ef |grep java or tomcat I am getting multiple process list. How do I get my exact tomcat process running and that is unique? via shell script? (4 Replies)
Discussion started by: Ghanshyam Ratho
4 Replies

3. Shell Programming and Scripting

Need generic command to get complete running process details

I am on SunOS and Linux I need generic command to get complete process details from which i will eventually extract socket details (listen address and port) ps -ef | ggrep -i server | ggrep -i mydomaindoes not yield a process that should have both the grep entries along with the listen... (8 Replies)
Discussion started by: mohtashims
8 Replies

4. UNIX for Beginners Questions & Answers

Idle command to kill the process running n unx box machine

Hi Team , I have one process named as cec_analysiseool that is running on unix box machine now i want to kill this process so please advise what will be the ideal command to kill this , what i have tried is :confused: kill -9 `ps -ef | grep cec_analysiseool | grep -v grep | awk '{print $2}'` (2 Replies)
Discussion started by: unclesamm
2 Replies

5. Shell Programming and Scripting

Command to know all the Current running process and how to kill

All, 1.What is the unix comand used for all current running process (Including All current running processes Parent ->child->subchild process) 2.If child and subchild processes are running then what is the unix command to kill parent and its all child subchild processes in UNIX. Kindly... (7 Replies)
Discussion started by: skp
7 Replies

6. Shell Programming and Scripting

Show running process command > 60 chars

Hi. I use this command to get list of running process: ps -ef|grep ICP|grep -v grep But how do I set the terminal to show full command? It seems that it always truncated to 60 chars no matter what options I put. e.g output oracle9 25011 24998 0 03:00:05 ? 0:00 /usr/bin/sh... (14 Replies)
Discussion started by: aimy
14 Replies

7. Shell Programming and Scripting

command to see process running at background

Hi , I want to see all the background process that are running in unix box machine...please guide me is there any specific command for that..since I am executing some scripts at background..!!:confused: (1 Reply)
Discussion started by: nks342
1 Replies

8. UNIX for Dummies Questions & Answers

Command to check if a particular process is running

Hi What is the best command to check if a particular process is running in a linux server or not To check any java process, I use the below command. ps -ef |grep jvm When I execute the above command, it lists me all the processess . The above command should ideally return only the... (6 Replies)
Discussion started by: vr3w3c9
6 Replies

9. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies

10. Shell Programming and Scripting

Command to find out "count" of running process ?

Hello Experts, Can any one help me out to find the command to get "count" of number of processes running in system. Basically i want to write one crone job to kill some process which making my system hanged. so have to do following things. 1) Find out the number of processes is running.... (4 Replies)
Discussion started by: MITESH KOTHARI
4 Replies
Login or Register to Ask a Question