Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-24-2010, 07:23 AM   #1
LQ Newbie
Registered: Sep 2010
Posts: 9

Rep: Reputation: 0
Post Screen start/stop script with a name?

Dear reader,

Im pretty new with Linux and this forum, so if I post this on the wrong section; please correct me.
atm I use a centos VPS with 1gb memory and enough space and brandwidth (if this info is off any use).

What I want to achieve is that I can start and quit a process that is running in a screen, with using a script.

Like that does "screen serverapp1 ./serverapp1"
and that does "kill serverapp1"

I already tried something like that, but it didnt work. The kill command only works with process ID's and that one is variable.



What I've tried (because google is my friend):

[servercod4001@datacenter-196 ~]$ screen -ls
There is a screen on:
11343.servercod4001 (Detached)
1 Socket in /var/run/screen/S-servercod4001.

[servercod4001@datacenter-196 ~]$ killall -u servercod4001
/proc is empty (not mounted ?)
[servercod4001@datacenter-196 ~]$ killall servercod4001
/proc is empty (not mounted ?)

Last edited by zondvloed; 09-24-2010 at 07:29 AM.
Old 09-24-2010, 08:45 AM   #2
Registered: Aug 2010
Distribution: Fedora, Centos, Debian
Posts: 49

Rep: Reputation: 7
Take a look at this.
Old 09-24-2010, 05:41 PM   #3
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,398
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
You can kill the screen session, which will kill all of its child processes. Use some variant of ps to find the PID to kill. You can also use ps to find the specific process running under screen, and kill that. If it is the last remaining window in the screen session, the screen will die with it. If the application running in screen is an interactive application that can take a command to quit, you can use the screen stuff command to stuff the quit command to the screen window, causing the application to terminate gracefully.
screen -S vijunk vi /tmp/junk.txt
ps -e f
 4757 ?        Ss     0:00 SCREEN -S vijunk vi /tmp/junk.txt
 4758 pts/111  Ss+    0:00  \_ vi /tmp/junk.txt

screen -list
There are screens on:
        4757.vijunk    (Multi, detached)
kill 4758
##  Or...
kill 4757
Stuff child vi session with quit command (may fail if vi is in insert mode, but the principle still holds)
screen -S vijunk -X stuff :q`echo -ne '\015'`
All of this can be scripted.

--- rod.

Last edited by theNbomr; 09-25-2010 at 12:35 PM.
Old 10-28-2010, 07:16 AM   #4
LQ Newbie
Registered: Sep 2010
Posts: 9

Original Poster
Rep: Reputation: 0
Correct solution: kill `pidof nameprocess`


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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Start and stop script with screensaver esoukenka Fedora 3 11-08-2011 07:04 AM
start script bash when system start,stop,reeboot, how ?? melmar Linux - General 4 12-10-2009 07:58 AM
AWK- processing data inside start/stop pairs but ignoring start/stop lines cliffoij Programming 2 10-15-2008 07:17 AM
custom init.d script will start but won't stop Qwerty9119 Red Hat 2 05-03-2007 01:51 PM
using cron to start and stop a bash script monty Linux - Software 2 03-20-2006 03:30 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:48 PM.

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