LinuxQuestions.org
Help answer threads with 0 replies.
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 11-20-2011, 08:45 PM   #1
metaf5
LQ Newbie
 
Registered: Aug 2011
Distribution: I'm kind of fond of Crunchbang...
Posts: 19

Rep: Reputation: Disabled
How to give realtime input to a background process?


So basically what is happening is I will start a process from a script. In this case the process is a Minecraft server, which is a java application. When I start it normally, my terminal will stay connected to the process, and I can enter commands to the application, like "stop" or "list users".

So, when I've started this application from a script, I don't have it open in a terminal to give it input, is there any way to 're-open' it, so me (or another script), could give this application commands? Ideally, I'd also be able to read the output it gives immediately after I give it a command.

I've heard I could use screen to do this, but is there any more elegant way? Screen seems a bit roundabout.
 
Old 11-20-2011, 09:11 PM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
I recently read the dd man page for running dd in the background. It mentions running the following kill command to bring it into the foreground and print out statistics of it and let it continue (does not kill it).

Code:
kill -USR1 pid
This assumes that you launch the command into the background using the current shell. If you sub-shell it (i.e. su - user -c somecommand) then that kill command won't work. I've tried it.

The kill man page mentions the -USR1 switch but does not specify what it is used for. So I still need to research more into it.

SAM
 
Old 11-21-2011, 02:22 PM   #3
metaf5
LQ Newbie
 
Registered: Aug 2011
Distribution: I'm kind of fond of Crunchbang...
Posts: 19

Original Poster
Rep: Reputation: Disabled
Based on my very limited knowledge of the topic, that actually sounds brilliant.

It's my understanding that when a process goes to the background, it forks off, and runs under user id 1, and kills the old process. So, it looks like this is just killing the process under UID 1, and restoring it. That's pretty sweet. Could do that in a script, and then give input to (what I think is) it's STDIN?

Edit: I'll give it a try before decrying it, but it looks like this is merely sending it a "User Defined Signal", and according to wikipedia, dd behaves notably in this manner, and it's unclear what this will do to other applications.

http://en.wikipedia.org/wiki/SIGUSR1

Last edited by metaf5; 11-21-2011 at 02:30 PM.
 
Old 11-21-2011, 03:21 PM   #4
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Does normal process control not work for you?

e.g.
Code:
somecommand &
jobs
fg 1
#press CTRL+Z to put in the background paused
bg 1
Also you might want to look at screen for session management.

Edit: I just reread your first post and saw you already discussed screen. You can pretty much disregard this post but I'll leave it up for archival purposes.

Last edited by sag47; 11-21-2011 at 03:25 PM.
 
Old 11-22-2011, 02:56 PM   #5
metaf5
LQ Newbie
 
Registered: Aug 2011
Distribution: I'm kind of fond of Crunchbang...
Posts: 19

Original Poster
Rep: Reputation: Disabled
Yeah looks like I have to use screen. (Just figured I'd post in case someone stumbles upon this thread in the future)
 
  


Reply

Tags
input, nohup, process, screen, scripting


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
64Studio realtime kernel and debian lenny realtime module buid error? stratotak Linux - Newbie 0 01-30-2009 10:57 PM
"ps" does not give nice value of process if realtime priority set... CJS Linux - General 1 07-16-2008 09:23 PM
How to find the process ID of process executing in the background akeneche Linux - Newbie 1 01-03-2008 10:08 AM
how to run any binary in background - background process tej Linux - Newbie 1 08-16-2004 12:27 AM
bash script to accept input ONLY until background process completes andrewstr Linux - Software 2 03-17-2004 12:02 PM

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

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

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