Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controlling Unix process from within C++

Status
Not open for further replies.

scecilia

Programmer
Jul 8, 2002
35
US
Hello,

I currently can make a system call from within my C++ as follows:

exec("ls -l"),

I want to run a more complicated program and be able to controll it from withing my C++. For example, if I run the xclock process, I cannot gain control of my program until I close the xclock window. How can I launch this xclock program and still be able to communicate with my C++ via the Unix prompt?

Thanks!!
 
Well, to have your program return immediately with the other program still running, you need to use [tt]fork()[/tt] and [tt]exec()[/tt]. It should be easy to find examples.

Then to have one control the other, you need to use some for of Interprocess Communication. That could be shared/mapped memory, semaphores, signals, pipes, etc. But you need to write both the controlling and controlled programs to use them.

Hope this helps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top