I want to write a program that same instance of it can be accesed by multiple comandlines. What kind of a program it should be and how to write it?
I want to write a program that same instance of it can be accesed by multiple comandlines. What kind of a program it should be and how to write it?
You can't have several users using the exact same instance of a program in memory. Each terminal (command line) has it's own environment, resources, etc, which might end up affecting the single instance in unpredictable ways. Such a feature might also open up considerable problems with security, synchronization, race conditions and resource sharing. You can, however, get several instances of the same program to communicate with each other and share some of their data. This can be achieved with pipes, sockets or shared memory. Your best bet is probably to Google for Linux IPC tutorials (IPC = Inter-Process Communication).
If you mean you want the program image to be shared in main memory, then that's already done automatically for read-only parts of the image.
If you mean you want the program image to be shared on disk, with two different names, make a link to it. Whatever it's invoked as will be argv[0]. I think this works for both hard and soft links.
You can set the program up so that when it starts, it uses IPC to check on a local socket. If something answers, it will know an instance of the program is already running, and this changes its behavior. If not, it takes over the socket and deals with any subsequent connections to it.
That's how, eg, most web browsers and editors work. If you use "firefox http://somepage" on the command line and firefox is already running, that page opens in the running firefox, instead of starting a new instance. This is because the first instance launched a server which then responds to requests on its local socket, and all instances use the same socket -- when they start, they check to see if one is already running, if it is, they send a request and exit. You can do this on a per user or global system level.
Last edited by MK27; 05-07-2011 at 06:04 PM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge