LinuxQuestions.org
Visit Jeremy's Blog.
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 01-20-2014, 09:15 PM   #1
errigour
Member
 
Registered: May 2009
Posts: 366

Rep: Reputation: 6
How can suspend a C program with C


I want to pretty much suspend a program with a command so that the program is still running but giving me a linux command prompt preferably in a manner that I can reverse if I want to run commands with the c program. Is that possible somehow?
 
Old 01-21-2014, 12:00 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,864
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
It is Ctrl+Z in the shell, and commands bg and fg. Read the manual for details.

Also you might think of this (within C program):
Code:
const char *shell= getenv ("SHELL");
if (!shell) shell= "/bin/sh";
system (shell);
 
1 members found this post helpful.
Old 01-21-2014, 07:39 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
You may want to describe exactly what you're trying to do. NevemTeve's answer is completely correct. But why do you feel you need to do this? Are you writing a program and doing something with it, are you running something else? Or is this a situation where it doesn't matter that the program continues to run or not; just you need to get back to a command prompt from time to time? Because you can do other things; either open a second command prompt if you're running a window manager, or run that program in the background when you first run it in the first place.
 
1 members found this post helpful.
Old 01-21-2014, 01:33 PM   #4
errigour
Member
 
Registered: May 2009
Posts: 366

Original Poster
Rep: Reputation: 6
Thanks.
 
Old 01-21-2014, 01:51 PM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Echoing the above sentiment ... in Perl circles we have a saying, TMTOWTDI = There's More Than One Way To Do It.™ And, this should give you pause.

Think very carefully about what exactly it is that you want to achieve, and exactly why. What is, if you will, the business purpose?

There are "several ways to do it," if you put your thinking-cap on. One of those, certainly, might be "to do, programmatically in C, what the user can already do in the Unix/Linux shell." But ... that is not "the only way," certainly, and it might well not be the best one. Think again in business terms:
  • What is the 'return on investment (ROI)' ?
  • What is the 'business risk,' and is that risk acceptable?
  • Is the money that will be spent in having a developer (i.e. "you") do it ... "money well-spent?" (Never mind if it actually does, or does not, "cost money.")

If I were your project-manager, I think that I'd probably nix the idea, because I'd be rather unconvinced that it was a good use of your time. Although, of course, I have no idea what your actual situation is, and therefore, whether I'd actually do such a thing or not. So, let's just say that "alarm bells are going off in my head" right now, and perhaps should also be going-off in yours. Those alarms are suggesting to me that maybe you just haven't turned-over all the toadstools yet. That there just might be an equally-satisfactory way to do it which might cost nothing at all.

Trying to put my finger on it ... "why is an application doing the shell's job?" Yeah, that might be 'it.'
 
  


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
LXer: Automatically Resume from Suspend to Ram and Suspend to Disk to Save Battery in Linux LXer Syndicated Linux News 0 05-10-2013 02:40 AM
Bash does not suspend/cancel pm-suspend theKbStockpiler Linux - General 1 11-05-2012 02:37 PM
pm-suspend vs. alternatives. gnome vs. enlightenment suspend. mkultra329 Linux - Newbie 1 02-19-2010 10:56 AM
Plz explain Suspend to Disk and Suspend to Ram pkhera_2001 Linux - Newbie 2 02-18-2008 07:23 AM
Program self-suspend PatrickNew Programming 7 04-19-2007 03:56 PM

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

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