Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I've been writing a simple interpreter, and came up with an idea to write an application server, this will host child applications which will run separate programs.

Basically, I want the server to be able to:
1. Run child processes simultaneously
2. At the same time, to be able to display a "shell-like program" which takes input to spawn more child processes and other options.
3. To be able to pause/continue interpreters on user input.

How would I go about doing this? I did assume the interpreters to spawn another "child thread" to read input from the server application (using sockets/shared memory maybe?).

Does the C standard provide a way to achieve this? Or do I have to look for OS-specific methods?

I've searched about fork() and execve(), but I want to keep the parent thread alive and responsive while running the child processes simultaneously (not consecutively), from what I've read, fork() can't seem to achieve that, or maybe I'm missing something?

I appreciate your help,
-sid2x
Posted
Updated 3-Jan-15 1:35am
v3
Comments
Sergey Alexandrovich Kryukov 3-Jan-15 17:59pm    
This is not really an "application service", but just some primitive shell. (I wonder why would you need it? :-)
—SA

1 solution

Yes you are missing something; fork exec allows you to spawn a child process while keeping the parent process running. See http://linux.die.net/man/2/fork[^] (or use your local man pages) for how to identify whether you are in the child or parent process.

That is how the interactive shells operate. You can do it in a simple console application that uses a loop to read commands from standard input and take action accordingly. Whether that action is done within the application, or by spawning a child process is dependent on the command.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Jan-15 18:00pm    
Right, a 5. I would add: this would be nothing like an "application server". The "interactive shell", exactly.
—SA
Richard MacCutchan 4-Jan-15 3:09am    
Why would you add that? It adds nothing useful for the OP, just a way of criticising them.
Sergey Alexandrovich Kryukov 4-Jan-15 14:32pm    
I strongly disagree. It's always useful to correct terminology, to help one to avoid confusions in future.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900