编写应用程序服务器 [英] Writing an application server

查看:94
本文介绍了编写应用程序服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我一直在编写一个简单的解释器,并想出了编写应用程序服务器的想法,这将托管将运行的子应用程序单独的计划。



基本上,我希望服务器能够:

1.同时运行子进程

2同时,能够显示一个类似shell的程序,它接受输入以产生更多的子进程和其他选项。

3.能够暂停/继续用户的解释器输入。



我该怎么做呢?我确实假设解释器产生另一个子线程来读取服务器应用程序的输入(使用套接字/共享内存可能?)。



C标准是否提供了实现此目的的方法?或者我是否必须寻找特定于操作系统的方法?



我搜索了fork()和execve(),但我想保留父线程同时(不是连续地)运行子进程时活着并且响应,从我读过的内容,fork()似乎无法实现,或者我可能缺少某些东西?



我感谢你的帮助,

-sid2x

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

推荐答案

是的你错过了什么; fork exec 允许您在保持父进程运行的同时生成子进程。请参阅 http://linux.die.net/man/2/fork [ ^ ](或使用您当地的手册页)了解如何确定您是否在孩子身边或者父进程。



这就是交互式shell运行的方式。您可以在一个简单的控制台应用程序中执行此操作,该应用程序使用循环从标准输入读取命令并相应地执行操该操作是在应用程序内完成还是通过生成子进程取决于命令。
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.


这篇关于编写应用程序服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆