LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-19-2011, 09:23 PM   #1
logme64
LQ Newbie
 
Registered: Oct 2011
Posts: 7

Rep: Reputation: Disabled
How to detaching and re-attaching to background processes?


Hi all

I'm making a terminal program( using c ), that will provide a shell. User can input commands and this program will give some feedback.

I have to make the program running all the way.
My thought is:
I provide a command called 'detach', when recieve 'detach' my program will go into background and return the bash to user.( I 'm not certain how to do it yet)
Then when user exec 'program attach' in bash, will re-attaching to background process and give user shell.( absolutely have no idea how to do it)

Will you please give me some hints to solve this two problems, especially the second one?

Thanks advanced.
 
Old 10-19-2011, 10:04 PM   #2
nguyeng
LQ Newbie
 
Registered: Jan 2011
Distribution: Slackware
Posts: 18

Rep: Reputation: 1
The functionally that you are explaining seems a lot like the program 'screen' try doing "screen PROGRAM-NAME" to 'detach' hit Ctrl+a+d. Attaching is done by screen -r. This should save you a lot of time instead of programming it yourself. For more information have a look at "man screen".
 
Old 10-19-2011, 11:25 PM   #3
logme64
LQ Newbie
 
Registered: Oct 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
Exactly. What is the general way to do it? Hate to read source code...
thanks.
 
Old 10-20-2011, 02:33 PM   #4
nguyeng
LQ Newbie
 
Registered: Jan 2011
Distribution: Slackware
Posts: 18

Rep: Reputation: 1
Screen is already installed on most distros. I'm unsure from your previous post but it seems like you don't want to use screen and want to embed the code into your program? Or maybe your not understanding exactly what screen is. In your terminal just issue the command
Code:
screen PROGRAM
where PROGRAM= any linux program that hangs and waits for user input. For example try
Code:
screen nano
Do what you want in nano hit CTRL+a+d to hop out of it and
Code:
screen -r
to resume where you left off. If you finished the rest of your terminal program you could try using screen on that to see if it behaves the way you want it to.

If you really insist on coding the detach and attach functionality yourself, my only guess is that you'll have to use fork() in order to send the program to the background. Try googling "c fork detach". I still think your better off using screen, unless this is some sort of school assignment or something for work. Good luck, hope you don't end up reading the source code because it is nasty

Last edited by nguyeng; 10-20-2011 at 02:34 PM. Reason: typo
 
  


Reply



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
background processes chameleon8636 Programming 6 10-15-2008 06:34 PM
Terminals and Background Processes dfego Linux - General 3 11-11-2006 08:52 AM
background processes digit Linux - Software 3 07-27-2003 12:27 PM
processes in background zetsui Linux - General 8 06-14-2003 12:52 PM
background processes hakum Programming 1 04-08-2002 10:29 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:52 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