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 |