简体   繁体   English

一旦进程开始使用shell脚本,就会抛出shell

[英]Disown shell once a process get started using shell script

I am trying to write a script for starting tomcat server which get disassociated from the shell once the execution of the script complete. 我正在尝试编写一个脚本来启动tomcat服务器,一旦脚本执行完成就会从shell中解除关联。 For example please see below snapshot of the screen. 例如,请参见下面的屏幕快照。

bash-3.00# ./startup.sh
Using CATALINA_BASE:   /opt/tomcat/6.0.32
Using CATALINA_HOME:   /opt/tomcat/6.0.32
Using CATALINA_TMPDIR: /opt/tomcat/6.0.32/temp
Using JRE_HOME:        /opt/jdk1.6.0_26/
Using CLASSPATH:       /opt/tomcat/6.0.32/bin/bootstrap.jar
bash-3.00# ps -eaf | grep tomcat
    root  4737  2945   0 02:45:53 pts/24      0:00 grep tomcat
    root  4734 29777   1 02:45:42 pts/24      0:19 /opt/jdk1.6.0_26//bin/java -Djava.util.logging.config.file=/opt/tomcat/6.0.32/c

Now as you can see that once the execution of the script complete the tomcat process is associated with pts/24 till I close the shell. 现在您可以看到,一旦脚本执行完成,tomcat进程就与pts / 24关联,直到我关闭shell。 But what I want is that even if the shell is kept open the process should show a behavior like below 但我想要的是,即使shell保持打开状态,该过程也应该显示如下所示的行为

bash-3.00# ps -eaf | grep tomcat
    root 13985  2945   0 22:40:13 pts/24      0:00 grep tomcat
    root 13977 29777   1 22:40:01 ?           0:22 /opt/jdk1.6.0_26//bin/java -Djava.util.logging.config.file=/opt/tomcat/6.0.32//

The operating System is Solaris. 操作系统是Solaris。 The various option I used to accomplish the same are using nohup, and disown but still the process is associated with shell. 我用来完成同样的各种选项是使用nohup和disown,但是这个过程仍然与shell相关联。

The other mechanism is to put in crontab or use svc to make the process start as system comes up ie daemon or we can write a small C program which forks a process and goes away. 另一种机制是放入crontab或使用svc使进程在系统启动时启动,即守护进程,或者我们可以编写一个小的C程序,它会分叉进程并消失。

Here please note that the process is running in background. 请注意,此过程在后台运行。

But I want to achieve the same using a shell or perl script. 但是我希望使用shell或perl脚本实现相同的功能。 So any thought on the same will help me a lot. 所以任何想法都会对我有所帮助。

Thanks in advance. 提前致谢。

Well, you could go and do all the hard work yourself, but why when there's a module for that: Proc::Daemon (Not sure if it works on solaris) 好吧,你可以自己去做所有艰苦的工作,但为什么当有一个模块: Proc :: Daemon (不确定它是否适用于solaris)

The documentation also describes the process used, which is useful for you to understand anyhow, if you decided to go ahead and craft your own daemonizing code. 该文档还描述了所使用的过程,如果您决定继续制作自己的守护程序代码,这对您无论如何都有用。

( nohup ./script.bash & )

带括号的子shell立即退出, ps -ef |grep script.bash返回:

501 59614     1   0   0:00.00 ttys005    0:00.00 /bin/bash ./script.bash

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM