?
Solved

call a process into the background

Posted on 2003-03-04
7
Medium Priority
?
207 Views
Last Modified: 2010-04-01
How to call a process into the background  using system () function in C++?
0
Comment
Question by:vksmoorthy
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
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!

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

569 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