让我的终端去吧 [英] Let My Terminal Go

查看:48
本文介绍了让我的终端去吧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我的应用程序的用户指向gVim中的行为,

文本编辑器,我想在我的

申请。


当从shell终端发起gVim时,它完全可以释放终端。无论你想要什么目的,你都可以继续使用终端

,包括关闭和退出它,

对运行的gVim实例没有任何影响。


如何在用python编写的应用程序中实现这一点?

我想相信它不会让我在新的应用程序中分配我的

应用程序处理。也许有信号我可以将b $ b发送到操作系统来实现这一点,对吗?


我们的帮助表示赞赏。


谢谢

解决方案

On Mon,2005-10-10 at 22:58 -0700, my ******** @ gmail.com 写道:

你好,

我的应用程序的用户指向我在gVim中的行为,
文本编辑器,我想在我的
应用程序中实现。

当gVim是从shell终端发起,它完全释放了终端。你可以继续使用终端来实现你想要的任何目的,包括关闭和退出它,对运行的gVim实例没有任何影响。

我如何在我的应用程序是用python编写的吗?
我想相信它并不涉及我在新进程中分配我的
应用程序。也许有信号我可以发送到操作系统来实现这一点,对吗?




gvim forks。你为什么要避免它?


import os,sys


pid = os.fork()

如果pid!= 0:

#export parent

sys.exit(0)

#child continue


my********@gmail.com 启发我们:

当从shell终端启动gVim时,它完全释放了
终端。 [...]我如何在我用
python编写的应用程序中实现它?




使用fork()并捕获HUP信号。 />

Sybren

-

世界的问题是愚蠢。并不是说应该对愚蠢的死刑进行处罚,但为什么我们不要仅仅拿掉

安全标签来解决问题呢? br />
Frank Zappa


" my ******** @ gmail.com" <我******** @ gmail.com>写道:

你好,

我的应用程序的用户指向我在gVim中的行为,
文本编辑器,我想在我的
应用程序中实现。

当从shell终端启动gVim时,它完全释放了终端。你可以继续使用终端来实现你想要的任何目的,包括关闭和退出它,对运行的gVim实例没有任何影响。

我如何在我的应用程序是用python编写的吗?
我想相信它并不涉及我在新进程中分配我的
应用程序。也许有信号我可以发送到操作系统来实现这一点,对吗?




需要做几件事。

首先,您需要将自己从您所在的会话中解脱出来。要执行

,您需要使用setsid系统调用。这在python中可用为

os.setsid。


最后,您需要从终端分离您的进程。你通过关闭所有引用它的文件描述符来做到这一点

。 stdin,

stdout和stderr应该做的伎俩。标准技巧是设置

将它们设置为/ dev / null。这必须发生在最后,所以如果在第二步中有

问题,写给stderr关于它确实有一些

好​​。


其次,你需要告诉启动你的shell,它可以继续使用
。执行此操作的标准方法是分叉您的进程,并且

具有父出口。这导致父shell认为你的
进程已经死了,所以完全忘了它。还有其他

方法可以做到这一点,但它们并不可靠。


完成所有这些事情的简单方法 - 无论如何,来自C - 与

守护进程(3)。这不是Python库的一部分。

解决问题的最简单方法可能是为

调用写一个包装器。如果守护进程存在于足够的系统上,那么将你的包装器作为一个

补丁提交给os模块是合适的。


< mike

-

Mike Meyer< mw*@mired.org> http://www.mired.org/home/mwm/

独立的WWW / Perforce / FreeBSD / Unix顾问,电子邮件以获取更多信息。


Hello,

A user of my application points me to a behavior in gVim,
the text editor, that I would like to implement in my
application.

When gVim is launched from a shell terminal, it completely
frees the terminal. You can continue to use the terminal for
whatever purpose you wish, including closing and exiting it,
without any effect on the running gVim instance.

How do I implement this in my application written in python?
I would like to believe it does not involve me forking my
application in a new process. Maybe there is signal I can
send to the operating system to achieve this, right?

Your help is appreciated.

Thanks

解决方案

On Mon, 2005-10-10 at 22:58 -0700, my********@gmail.com wrote:

Hello,

A user of my application points me to a behavior in gVim,
the text editor, that I would like to implement in my
application.

When gVim is launched from a shell terminal, it completely
frees the terminal. You can continue to use the terminal for
whatever purpose you wish, including closing and exiting it,
without any effect on the running gVim instance.

How do I implement this in my application written in python?
I would like to believe it does not involve me forking my
application in a new process. Maybe there is signal I can
send to the operating system to achieve this, right?



gvim forks. Why do you want to avoid it?

import os, sys

pid = os.fork()
if pid !=0:
# exit parent
sys.exit(0)
# child continues


my********@gmail.com enlightened us with:

When gVim is launched from a shell terminal, it completely frees the
terminal. [...] How do I implement this in my application written in
python?



Using fork() and by catching the HUP signal.

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don''t we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa


"my********@gmail.com" <my********@gmail.com> writes:

Hello,

A user of my application points me to a behavior in gVim,
the text editor, that I would like to implement in my
application.

When gVim is launched from a shell terminal, it completely
frees the terminal. You can continue to use the terminal for
whatever purpose you wish, including closing and exiting it,
without any effect on the running gVim instance.

How do I implement this in my application written in python?
I would like to believe it does not involve me forking my
application in a new process. Maybe there is signal I can
send to the operating system to achieve this, right?



Several things need to happen.

First, you need to take yourself out of the session you are in. To do
that, you use the setsid system call. This is available in python as
os.setsid.

Last, you need to detach your process from the terminal. You do that
by closing all the file descriptors you have that reference it. stdin,
stdout and stderr should do the trick. The standard trick is to set
set them to /dev/null. This has to happen last, so that if there are
problems in the second step, writing to stderr about it does some
good.

Second, you need to tell the shell that launched you that it can
continue. The standard way to do this is to fork your process, and
have the parent exit. That causes the parent shell to think your
process is dead, and so forget about it completely. There are other
ways to do this, but they aren''t as reliable.

The easy way to do all these things - from C, anyway - is with
daemon(3). That isn''t wrapped as part of the Python library. The
easiest way to solve your problem may be write a wrapper for that
call. If daemon exists on enough systems, submitting your wrapper as a
patch to the os modulee would be appropriate.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.


这篇关于让我的终端去吧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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