编写应用程序服务器

编程入门 行业动态 更新时间:2024-10-26 13:20:37
本文介绍了编写应用程序服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好, 我一直在编写一个简单的解释器,并想出了编写应用程序服务器的想法,这将托管将运行的子应用程序单独的计划。 基本上,我希望服务器能够: 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 允许您在保持父进程运行的同时生成子进程。请参阅 linux.die/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 linux.die/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.

更多推荐

编写应用程序服务器

本文发布于:2023-07-27 14:09:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222779.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   服务器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!