LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How can suspend a C program with C (https://www.linuxquestions.org/questions/programming-9/how-can-suspend-a-c-program-with-c-4175491963/)

errigour 01-20-2014 09:15 PM

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?

NevemTeve 01-21-2014 12:00 AM

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);


rtmistler 01-21-2014 07:39 AM

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.

errigour 01-21-2014 01:33 PM

Thanks.

sundialsvcs 01-21-2014 01:51 PM

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.'


All times are GMT -5. The time now is 09:12 PM.