invoking an application with in another application

S

sharada

Guest
Hai ,
i am new to mac.i donot know how to do the things here .

i want to create two applications , i.e. app1 and app2.

All app1 does is invokes app2 if not started. Sleeps for some time (i.e. 60 sec). Then exits.
App1 basically invokes app2 the very first time it is run. Next instance of App1 simply checks to see if App2 is running. If so, prints a message like App2 is already running. So both App1 instances will essentially communicate with App

When one instance of App1 exits, we do not shutdown App2 (since other instance of App1 can still be talking to it).

When second instance of App1 exits (last instance of App1), it shuts down App2 and then exits.i want to write these two applications in "C".


please help me regarding this , if possible send me some code samples.

Thanks & Regards,
sharada..
 

rman


Retired Staff
Joined
Dec 24, 2002
Messages
12,637
Reaction score
168
Points
63
Location
Los Angeles, California
Your Mac's Specs
14in MacBook Pro M1 Max 32GB 2TB
It appears to me, that you want a shell script call app1 and a C application called app2. The shell script app1 will have a loop and a if then statement of sort. It will then check to see if app2 is running if not it start it, and then go to sleep for a short period of time. Upon waking it will check for app2, and repeat the cycle. I don't see app1 communicating with app2, just checking to see if it is up. We would need more to get a feel for what you are trying to do.
 
OP
S

sharada

Guest
hai ,
thanks for response ,i donot want to use shell script. first of all i need to run one application sum with in other application Launcher(like create process in windows), Launcher invokes sum if not started. Sleeps for some time (i.e. 60 sec). Then exits.
Launcher basically invokes sum the very first time it is run. Next instance of Launcher simply checks to see if sum is running. If so, print a message like sum is already running. So both Launcher instances will essentially communicate with sum.i need to do the code in pure c. ( nothing but "C") first please ,guide me to this things first.

Thanks & Regards,
sharada..
 
Joined
Jun 6, 2006
Messages
1,153
Reaction score
94
Points
48
Your Mac's Specs
MacBook 2.0GHz White, 512MB RAM, 60GB HDD
There are many ways to do this, ranging from the simplistic to the insanely complex. From a terminal, type:

man 3 exec

That will detail how to launch programs from within a C program. Also look at:

man 3 fork

for splitting off new processes.

As for checking if it's already running, you could do it with a simple lock file in the user's home directory, or something complex involving semaphores, signals, shared memory or any number of other IPC mechanisms. It's quite a complex subject; searching the web for 'unix ipc' will give you many pointers.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top