?
Solved

call a process into the background

Posted on 2003-03-04
7
Medium Priority
?
203 Views
Last Modified: 2010-04-01
How to call a process into the background  using system () function in C++?
0
Comment
Question by:vksmoorthy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 3

Expert Comment

by:cmaryus
ID: 8063721
When you run system, it will open a dos prompt from where the command will be run.
To run a process in the background use Win API CreateProcess.
0
 
LVL 8

Expert Comment

by:mnashadka
ID: 8063729
If you're in another operating system, you can use exec to create a background process.
0
 

Author Comment

by:vksmoorthy
ID: 8063832
In Unix operating system
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vksmoorthy
ID: 8063854
In Unix operating system
0
 
LVL 3

Accepted Solution

by:
cmaryus earned 200 total points
ID: 8064075
use execve, but you must be carefull that after the call to execve the process you started will run instead of the caller process !!! That's way the best way is to use a fork:

int my_system (const char *command)
{
      int pid, status;

      if (command == 0)
          return 1;
      pid = fork();
      if (pid == -1)
          return -1;
      if (pid == 0) {
          char *argv[4];
          argv[0] = "sh";
          argv[1] = "-c";
          argv[2] = command;
          argv[3] = 0;
          execve("/bin/sh", argv, environ);
          exit(127);
      }
      do {
          if (waitpid(pid, &status, 0) == -1) {
              if (errno != EINTR)
                  return -1;
          } else
              return status;
      } while(1);
}
0
 
LVL 1

Expert Comment

by:sarda_ramesh
ID: 8064762
simply try this ...

system ("process-name &");

this will make the process to run in background

regards
ramesh
0
 
LVL 30

Expert Comment

by:Axter
ID: 9374689
vksmoorthy,
No comment has been added lately (196 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to cmaryus http:#8064075

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

Axter
EE Cleanup Volunteer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question