jar畅游Linux后台

Linux系统运行jar包

jar通常方式

java -jar xxx.jar

特点:当前ssh窗口被锁定,可按CTRL + C打断程序运行,或直接关闭窗口,程序退出

jar后台运行方式

方式一

java -jar xxx.jar &	//&代表在后台运行

特点:当前ssh窗口不被锁定,但是当窗口关闭时,程序中止运行

方式二

nohup java -jar xxx.jar &
//nohup 意思是不挂断运行命令,当账户退出或终端关闭时,程序仍然运行

当用 nohup 命令执行作业时,缺省情况下该作业的所有输出被重定向到nohup.out的文件中(即输出内容不打印到屏幕上,而是输出到nohup.out文件中),除非另外指定了输出文件

nohup java -jar xxx.jar >/dev/null  &	//指定输出到/dev/null文件中,没有则会自动创建

特点:不挂断运行命令,当账户退出或终端关闭时,程序仍然运行

查看后台运行任务

jobs

那么就会列出所有后台执行的作业,并且每个作业前面都有个编号。
如果想将某个作业调回前台控制,只需要 fg + 编号即可。

fg 520

查看某端口占用的线程的pid

netstat -nlp |grep :8080

linux 进程查看及杀死进程

ps -ef |grep java

ps:将某个进程显示出来
-A  显示所有程序。
-e  此参数的效果和指定"A"参数相同。
-f  显示UID,PPIP,C与STIME栏位。
grep命令是查找
中间的|是管道命令 是指ps命令与grep同时执行

这条命令的意思是显示有关java有关的进程

# kill[参数][进程号]
kill -9 8888

kill就是给某个进程id发送了一个信号。默认发送的信号是SIGTERM,而kill -9发送的信号是SIGKILL,即exit。exit信号不会被系统阻塞,所以kill -9能顺利杀掉进程。当然你也可以使用kill发送其他信号给进程。

附录:各种信号及其用途

Signal Description Signal number
SIGABRT Process aborted 6
SIGALRM Signal raised by alarm 14
SIGBUS Bus error: “access to undefined portion of memory object” 7
SIGCHLD Child process terminated, stopped (or continued*) 17
SIGCONT Continue if stopped 18
SIGFPE Floating point exception: “erroneous arithmetic operation” 8
SIGHUP Hangup 1
SIGILL Illegal instruction 4
SIGINT Interrupt 2
SIGKILL Kill (terminate immediately) 9
SIGPIPE Write to pipe with no one reading 13
SIGQUIT Quit and dump core 3
SIGSEGV Segmentation violation 11
SIGSTOP Stop executing temporarily 19
SIGTERM Termination (request to terminate) 15
SIGTSTP Terminal stop signal 20
SIGTTIN Background process attempting to read from tty (“in”) 21
SIGTTOU Background process attempting to write to tty (“out”) 22
SIGUSR1 User-defined 1 10
SIGUSR2 User-defined 2 12
SIGPOLL Pollable event 29
SIGPROF Profiling timer expired 27
SIGSYS Bad syscall 31
SIGTRAP Trace/breakpoint trap 5
SIGURG Urgent data available on socket 23
SIGVTALRM Signal raised by timer counting virtual time: “virtual timer expired” 26
SIGXCPU CPU time limit exceeded 24
SIGXFSZ File size limit exceeded 25
原创文章 6 获赞 8 访问量 315

猜你喜欢

转载自blog.csdn.net/weixin_46424798/article/details/105806533