0

I'm running a program on a Debian machine. It run it in the background by using the following command: "nohup ./samp03svr &". As I'm told the "&" symbol is what makes it run in the background.

My problem is that I need to send commands to the program later. Can I get it back from background somehow?

I'm using PuTTy tu access my machine, if that helps.

Justas S
  • 584
  • 4
  • 12
  • 34

1 Answers1

0

Yes you can do this with the fg command. I'm going to show this with a silly ls command which finishes long before you get the chance to give commands (I assume you use something like stdin to get them to your program)

eg:

ls &
[1] 10970 #you'll see output similar to this.

fg %1 #get  job one back to the foreground hence the name fg. 

notice the [1] 10970 the[1] is the jobnumber you can also use the command jobs to show which jobs are currently in the background. Ofcourse you should replace ls with nohup ./samp03svr &

hope this helps cheers,

hetepeperfan
  • 4,292
  • 1
  • 29
  • 47
  • Something happened, but i'm not sure what.. And not what I meant sadly. What should I do insted of "ls", as I know it displays files in my current dir. I'll try to explain what I need, because I believe you misunderstood me(or I did): There's a program running(on Windows it's like a console) and I want to send a command "say text" to it, which should act accordingly in the game – Justas S Dec 02 '13 at 12:32
  • please see my edit. Also your question is a bit vague, since you don't specify what you mean by a command. How your program should get those commands etc. – hetepeperfan Dec 02 '13 at 12:33
  • Ah, but that will run it again, wont it ? It might be hard to understand, because I do not know correct terms... By "Send commands" I want to do something simmiliar to writing text into console on Windows – Justas S Dec 02 '13 at 12:37
  • Nope the program state is in the background. fg just gets the program back to the foreground so you are able to provide input via the standard input for example. – hetepeperfan Dec 02 '13 at 12:39
  • Well I now can to write text, I'll asume that it's sent to the program and it just runs differently on linux and I can't use it that way... One more question, how do I send it back to background? – Justas S Dec 02 '13 at 12:45
  • by using the keycombination `ctrl+z`. But specify what you mean "it's send to the program". You should tell by what way it should be send to the program, since it doesn't occur by magic. – hetepeperfan Dec 02 '13 at 12:47
  • That stopped the program – Justas S Dec 02 '13 at 12:49
  • No that does't stop the program is puts the program in the background see eg: http://stackoverflow.com/questions/625409/how-do-i-put-an-already-running-process-under-nohup – hetepeperfan Dec 02 '13 at 12:52
  • About that sending, the console knows how to send it to the program. I need to send it to the console. About stopping. Recap, I run it with nohup. When I want i use fg to get it from the background. And then if I press **ctrl+z** it outputs: [2]+ stopped nohup ./samp03svr – Justas S Dec 02 '13 at 13:00
  • and then run bg %2 and then the program will run in the back ground. – hetepeperfan Dec 02 '13 at 13:04
  • Finally. I didn't quite achieve what I wanted but atleast I learned something. I thankyou for your patience and help – Justas S Dec 02 '13 at 13:07