包含nohupjava详解的词条
本篇文章给大家谈谈nohupjava详解,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
使用xshell的nohup&命令在服务器上运行Java程序
您好,在网上有挺多版本,C JAVA的都有,我找了一个还可以,有源码,大概试了试效果还不错。需要下载一个ganymed-ssh2-build210 代码部分大概是这样的。
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import ch.ethz.ssh2.ChannelCondition;
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;
import ch.ethz.ssh2.StreamGobbler;
public class RmtShellExecutor {
private Connection conn;
private String ip;
private String usr;
private String psword;
private String charset = Charset.defaultCharset().toString();
private static final int TIME_OUT = 1000 * 5 * 60;
public RmtShellExecutor(ShellParam param) {
this.ip = param.getIp();
this.usr = param.getUsername();
this.psword = param.getPassword();
}
class ShellParam{
String ip;
String usr;
String psword;
String getIp(){
return ip;
};
String getUsername(){
return usr;
}
String getPassword(){
return psword;
}
}
public RmtShellExecutor(String ip, String usr, String ps) {
this.ip = ip;
this.usr = usr;
this.psword =ps;
}
private boolean login() throws IOException {
conn = new Connection(ip);
conn.connect();
return conn.authenticateWithPassword(usr, psword);
}
public int exec(String cmds) throws Exception {
InputStream stdOut = null;
InputStream stdErr = null;
String outStr = "";
String outErr = "";
int ret = -1;
try {
if (login()) {
// Open a new {@link Session} on this connection
Session session = conn.openSession();
// Execute a command on the remote machine.
session.execCommand(cmds);
stdOut = new StreamGobbler(session.getStdout());
outStr = processStream(stdOut, charset);
stdErr = new StreamGobbler(session.getStderr());
outErr = processStream(stdErr, charset);
session.waitForCondition(ChannelCondition.EXIT_STATUS, TIME_OUT);
System.out.println("" + outStr);
ret = session.getExitStatus();
} else {
System.out.println("登录远程机器失败"+ ip);
}
} finally {
if (conn != null) {
conn.close();
}
}
return ret;
}
private String processStream(InputStream in, String charset) throws Exception {
byte[] buf = new byte[1024];
StringBuilder sb = new StringBuilder();
while (in.read(buf) != -1) {
sb.append(new String(buf, charset));
}
return sb.toString();
}
public static void main(String args[]) throws Exception {
RmtShellExecutor exe = new RmtShellExecutor("", "", "");
System.out.println(exe.exec("ls"));
}
}
nohup 详解 Python不挂断运行后台程序
原文链接
回到顶部
nohup 命令运行由 Command参数和任何相关的 Arg参数指定的命令,忽略所有挂断(SIGHUP)信号。在注销后使用 nohup 命令运行后台中的程序。要运行后台中的 nohup 命令,添加 ( 表示“and”的符号)到命令的尾部。
nohup 是 no hang up 的缩写,就是不挂断的意思。
nohup命令:如果你正在运行一个进程,而且你觉得在退出帐户时该进程还不会结束,那么可以使用nohup命令。该命令可以在你退出帐户/关闭终端之后继续运行相应的进程。
在缺省情况下该作业的所有输出都被重定向到一个名为nohup.out的文件中。
回到顶部
在上面的例子中,0 – stdin (standard input),1 – stdout (standard output),2 – stderr (standard error) ;
21是将标准错误(2)重定向到标准输出(1),标准输出(1)再被重定向输入到myout.file文件中。
这是放在crontab中的定时任务,晚上22点时候怕这个任务,启动这个python的脚本,并把日志写在download_dfcf_pdf_to_oss.log文件中
回到顶部
: 指在后台运行
nohup : 不挂断的运行,注意并没有后台运行的功能,,就是指,用nohup运行命令可以使命令永久的执行下去,和用户终端没有关系,例如我们断开SSH连接都不会影响他的运行,注意了nohup没有后台运行的意思;才是后台运行
是指在后台运行,但当用户推出(挂起)的时候,命令自动也跟着退出
那么,我们可以巧妙的吧他们结合起来用就是
nohup COMMAND
这样就能使命令永久的在后台执行
例如:
1. sh test.sh
将sh test.sh任务放到后台 ,即使关闭xshell退出当前session依然继续运行,但 标准输出和标准错误信息会丢失(缺少的日志的输出)
将sh test.sh任务放到后台 ,关闭xshell,对应的任务也跟着停止。
2. nohup sh test.sh
将sh test.sh任务放到后台,关闭标准输入, 终端不再能够接收任何输入(标准输入) ,重定向标准输出和标准错误到当前目录下的nohup.out文件,即使关闭xshell退出当前session依然继续运行。
3. nohup sh test.sh
将sh test.sh任务放到后台,但是依然可以使用标准输入, 终端能够接收任何输入 ,重定向标准输出和标准错误到当前目录下的nohup.out文件,即使关闭xshell退出当前session依然继续运行。
回到顶部
nohup命令详解
nohup命令运行由Command参数和任何相关的Arg参数指定的命令,忽略所有挂断(SIGHUP)信号。在注销后使用nohup命令运行后台中的程序。要运行后台中的nohup命令,添加(表示“and”的符号)到命令的尾部。
nohup命令是英语词组nohangup的缩写,意思是不挂断,也就是指程序不退出。这个命令会使程序忽略HUP信号,保证程序能够正常进行。HUP信号有些人可能比较陌生,它是在终端被中止的时候向它所关联的进程所发出的信号,进程收到这个信号后就会中止运行。所以如果你不希望进程被这个信号干掉的话,就可以忽略这个信号。而nohup命令做的就是这个事情。
linux nohup 启动java工程问题
1) 在ECLIPSE下面EXPORT成为RUNNABLE JAR FILE。
2)拷贝1)中生成的JAR包,到LINUX中去。
3)随便搞个什么名字的.SH文件,里面输入java -jar XXX.jar
nohupjava详解的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、nohupjava详解的信息别忘了在本站进行查找喔。
发布于:2022-11-23,除非注明,否则均为
原创文章,转载请注明出处。