在一个进程中运行多个程序? [英] Running multiple programms in one process?

查看:134
本文介绍了在一个进程中运行多个程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我有一个正在运行的进程,我想在当前进程中加载​​另一个exe文件(另一个程序)(在一个进程中有多个程序)。可能吗?有谁能够帮我?谢谢。

Hi! I have a running one process and I want load another exe file (another program) in current process (multiple programms in one process). Is it possible? Can anybody help me? Thanks.

推荐答案

不,这是不可能的,因为程序和进程之间没有区别,除了第一个是静态的,第二个是运行的。



我的意思是,进程是正在运行的程序。一个过程可以然而有几个线程 ...



看看(可能)更好的解释: http://wiki.answers.com/Q/What_is_the_difference_between_a_process_and_a_program [ ^ ]



No, that is not possible since there is no difference between a program and process apart from the fact that the first is static and the second running.

I mean, the process is the running program. One process can however have several threads ...

Take a look at (possibly) better explaination: http://wiki.answers.com/Q/What_is_the_difference_between_a_process_and_a_program[^]

A process is an instance or invocation of a program - you can have for example two processes running the same program at the same time e.g. you can have a calculator program open twice, this is two processes but only one program.

Some programs connect to and issue instructions to an existing process if one exists. Firefox is one example of such a program (when running under Linux at least).


A process is a program in execution. It is an active entity whereas a program is an static entity. It is a set of instructions.

In the abstract, think of a program as a set of instructions written down to do something, like the recipe for a cake. Taking those instructions and actually following them (i.e. executing them) results in an actual entity - a process in the computer world, or a specific cake using the recipe analogy. Thus, a process is the result of executing a program, just like the cake I'm eating is a results of the Betty Crocker recipe. As noted above, you have have multiple processes of one program, just like I can make many cakes from a single recipe.


这个问题只是有限的意义。这取决于你所谓的程序。如果某些代码在某个进程中执行,而不是作为一个单独的进程执行,我不会将其称为程序。



这是一些背景知识。 EXE文件是PE文件,首先它具有一些特殊签名的入口点,用于在加载应用程序时执行:

http://en.wikipedia.org/wiki/Main_function_%28programming%29 [ ^ ]。



原则上,你可以加载使用 LoadLibrary 在运行时从已执行的进程中获取此类模块。我可以想象有一些导出函数可以使用 GetProcAddress 调用。据我所知,我尝试过这样的事情。我甚至可以想象你可以直接或间接地调用函数 main 。但即使你这样做,你能称之为运行程序吗?根据定义,我不认为它是一个正在运行的程序。而且你很难从这些活动中获得任何好处,除非那些EXE文件是专门为这些技巧而设计的,但它可能具有任何实际意义。



实际意义是你的想法完全缺乏的东西。如果这些EXE文件不是为此设计的,那么加载它们将毫无用处。但是,如果您想为这种技术开发EXE模块,为什么不开发常规DLL,以完全控制您的功能?我认为没有理由。



另一方面,如果您的EXE文件是简单的仅限控制台的应用程序,那么您可以简单地将其作为单独的进程运行并重新指导所有控制台输出。您还可以使用 WaitForMultipleObjects 等待进程完成。最好在单独的帖子中进行。



-SA
The question makes only limited sense. It depends on what you call a "program". If some code is executed inside some process, and not a as a separate process, I would not call it a "program".

Here is some background. EXE file is the PE file which, first of all has such thing as the entry point of some special signatures intended to be executed when the application is loaded:
http://en.wikipedia.org/wiki/Main_function_%28programming%29[^].

In principle, you can load such module from your already executing process during run-time using LoadLibrary. I can imagine that is has some exported function which you can call using GetProcAddress. As far as I can remember, I experimented with such things. I can even imagine that you can call the function main, directly or indirectly. But even if you do, can you call it "running a program"? I would not consider it as a running program, by definition. And you can hardly get anything good from such activities, unless those EXE files are specially designed for such tricks, but may it make any practical sense.

The practical sense is something which your idea lacks completely. If those EXE files are not designed for this, loading them would be useless. But if you want to develop EXE modules for such technique, why not developing the "regular" DLLs, to get full control over your functionality? I see no reason.

From the other hand, if your EXE files are simple console-only application, you can simply run then as separate processes and re-direct all the console output. You can also wait for the process completion using WaitForMultipleObjects. It would be the best to do in a separate thread.

—SA


这篇关于在一个进程中运行多个程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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