linux shell关掉后java程序(进程名abc)仍能运行,用ps -ef|grep abc能查到进程名 我将java程序写到一个shell文件中,并且让java程序在后台执行( java yourFile & ),这样关掉shell后,java程序不会被关掉 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1简单java MyExample &加了&表示后台运行2的方式太多了涉及到进程间通讯的内容 谢谢大家的回答,我的测试结果是:“后台运行”表示可以在当前shell执行其它命令,但关掉linux shell(或telnet的dos窗口)后,此进程就关掉了。我的测试过程:[root@localhost test]# ./javac.sh ScheduleBashRun.java[root@localhost test]# ./java.sh ScheduleBashRun &结果我关掉“telnet的dos窗口”后,ScheduleBashRun(包括其启动的线程)都关掉了。测试源代码:javac.sh/usr/java/j2sdk1.4.0/bin/javac $1 $2 $3java.sh/usr/java/j2sdk1.4.0/bin/java $1 $2 $3ScheduleBashRun.javaimport java.io.FileOutputStream;import java.io.OutputStreamWriter;import java.util.Timer;import java.util.TimerTask;import java.awt.Toolkit;public class ScheduleBashRun { Timer timer; public ScheduleBashRun(int milliseconds) { timer = new Timer(); timer.schedule(new RemindTask(), 0, milliseconds); } class RemindTask extends TimerTask { int countSchedule=20; FileOutputStream fos = null; OutputStreamWriter outkk = null; public RemindTask() { try { this.fos = new FileOutputStream("result.txt"); this.outkk = new OutputStreamWriter(fos); } catch(Exception e) { e.printStackTrace(); } } public void run() { //System.out.println("left count:" + this.countSchedule); if( countSchedule<1 ) { try { this.outkk.close(); this.fos.close(); } catch(Exception e) { e.printStackTrace(); } System.exit(0); } else { try { this.outkk.write("test" + this.countSchedule + "\r\n"); this.countSchedule--; } catch(Exception e) { e.printStackTrace(); } } } } public static void main(String args[]) { System.out.println("About to schedule task."); new ScheduleBashRun(1000); System.out.println("Task scheduled."); }} java.lang.ClassNotFoundException错误 Java中byte是不是无意义的? jcreator环境下的事件监听有问题,帮忙查错 请高手指教,找错!~ JAVA正则表达问题 越简单的问题越不懂 各位高手,大侠,仁兄,快帮帮小弟吧! JTextArea 中如何设置不同的文本格式 事件监听器的问题 only instances of classes are subject to garbage collection not primitives.怎么翻译? String 与 byte之间的转换 全面提升你的Jbuilder速度
加了&表示后台运行2的方式太多了
涉及到进程间通讯的内容
“后台运行”表示可以在当前shell执行其它命令,但关掉linux shell(或telnet的dos窗口)后,此进程就关掉了。我的测试过程:
[root@localhost test]# ./javac.sh ScheduleBashRun.java
[root@localhost test]# ./java.sh ScheduleBashRun &
结果我关掉“telnet的dos窗口”后,ScheduleBashRun(包括其启动的线程)都关掉了。测试源代码:
javac.sh
/usr/java/j2sdk1.4.0/bin/javac $1 $2 $3java.sh
/usr/java/j2sdk1.4.0/bin/java $1 $2 $3ScheduleBashRun.java
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.Timer;
import java.util.TimerTask;
import java.awt.Toolkit;
public class ScheduleBashRun {
Timer timer;
public ScheduleBashRun(int milliseconds) {
timer = new Timer();
timer.schedule(new RemindTask(), 0, milliseconds);
}
class RemindTask extends TimerTask {
int countSchedule=20;
FileOutputStream fos = null;
OutputStreamWriter outkk = null;
public RemindTask() {
try {
this.fos = new FileOutputStream("result.txt");
this.outkk = new OutputStreamWriter(fos);
} catch(Exception e) {
e.printStackTrace();
}
}
public void run() {
//System.out.println("left count:" + this.countSchedule);
if( countSchedule<1 ) {
try {
this.outkk.close();
this.fos.close();
} catch(Exception e) {
e.printStackTrace();
}
System.exit(0);
} else {
try {
this.outkk.write("test" + this.countSchedule + "\r\n");
this.countSchedule--;
} catch(Exception e) {
e.printStackTrace();
}
}
}
} public static void main(String args[]) {
System.out.println("About to schedule task.");
new ScheduleBashRun(1000);
System.out.println("Task scheduled.");
}
}