[root@test]$ cat test.cpp #include <stdio.h> #include <unistd.h> int main(void) { int i = 0; for(i==0;i<100;i++) { sleep(2); printf("Hello World\n"); } } [root@test]$ gcc test.cpp -o test.out [root@test]$ ./test.out & [1] 35166 [root@test]$ Hello World Hello World ^C [root@test]$ Hello World ps Hello World -lf F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 4 S root 34824 34817 0 80 0 - 28750 do_wai 22:49 pts/15 00:00:00 -bash 0 S root 35166 34824 0 80 0 - 1056 hrtime 22:51 pts/15 00:00:00 ./test.out 0 R root 35174 34824 0 80 0 - 38356 - 22:51 pts/15 00:00:00 ps -lf [root@test]$ Hello World
[root@test]$ ps -lf F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 4 S root 34824 34817 0 80 0 - 28750 do_wai 22:49 pts/15 00:00:00 -bash 0 R root 38815 34824 0 80 0 - 38356 - 23:30 pts/15 00:00:00 ps -lf [root@test]$ bash [root@test]$ ps -lf F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 4 S root 34824 34817 0 80 0 - 28750 do_wai 22:49 pts/15 00:00:00 -bash 4 S root 38838 34824 0 80 0 - 28715 do_wai 23:30 pts/15 00:00:00 bash 0 R root 38882 38838 0 80 0 - 38356 - 23:30 pts/15 00:00:00 ps -lf [root@test]$ exit exit [root@test]$ ps -lf F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 4 S root 34824 34817 0 80 0 - 28750 do_wai 22:49 pts/15 00:00:00 -bash 0 R root 38900 34824 0 80 0 - 38356 - 23:30 pts/15 00:00:00 ps -lf
[root@test]$ ./test.out 1> std.out 2> std.err & [1] 41371 [root@test]$ ps -lf F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 4 S root 34824 34817 0 80 0 - 28750 do_wai Apr21 pts/15 00:00:00 -bash 0 S root 41371 34824 0 80 0 - 1056 hrtime 00:00 pts/15 00:00:00 ./test.out 0 R root 41379 34824 0 80 0 - 38356 - 00:00 pts/15 00:00:00 ps -lf [root@test]$ cat std.out [root@test]$
[root@test]$ cat test.cpp #include <stdio.h> #include <unistd.h> int main(void) { int i = 0; for(i==0;i<10;i++) { sleep(2); printf("Hello World\n"); } } [root@test]$ gcc test.cpp -o test.out [root@test]$ cat std.out [root@test]$ ./test.out 1> std.out 2> std.err & [1] 41775 [root@test]$ ps -lf F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 4 S root 34824 34817 0 80 0 - 28750 do_wai Apr21 pts/15 00:00:00 -bash 0 S root 41775 34824 0 80 0 - 1056 hrtime 00:04 pts/15 00:00:00 ./test.out 0 R root 41779 34824 0 80 0 - 38356 - 00:04 pts/15 00:00:00 ps -lf [root@test]$ ps -lf F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 4 S root 34824 34817 0 80 0 - 28750 do_wai Apr21 pts/15 00:00:00 -bash 0 R root 41870 34824 0 80 0 - 38356 - 00:05 pts/15 00:00:00 ps -lf [1]+ Done ./test.out > std.out 2> std.err [root@test]$ cat std.out Hello World Hello World Hello World ... [root@test]$
[root@test:/home/robot] # ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.4 0.0 171620 11604 ? Ss 14:16 0:26 /usr/lib/systemd/systemd --switched-root --system --deserialize 17 systemd+ 591 0.0 0.0 19152 6400 ? Ss 14:17 0:00 /usr/lib/systemd/systemd-networkd avahi 761 0.0 0.0 9656 6244 ? Ss 14:17 0:04 avahi-daemon: running [test root 766 0.0 0.0 6028 2152 ttyS0 Ss+ 14:17 0:00 /sbin/agetty -o -p -- \u --keep-baud 115200,38400,9600 ttyS0 vt220 root 767 0.0 0.0 6388 1604 tty1 Ss+ 14:17 0:00 /sbin/agetty -o -p -- \u --noclear tty1 linux root 777 0.0 0.0 614464 18100 ? Ssl 14:17 0:04 python3 -u /opt/nokia/libexec/StorageUtils/script/lsa/local_storage_agent.py avahi 778 0.0 0.0 8944 432 ? S 14:17 0:00 avahi-daemon: chroot helper _test+ 779 0.0 0.0 164384 5784 ? Ssl 14:17 0:01 /opt/nokia/bin/eventdaemon --global root 784 0.0 0.0 0 0 ? Z 14:17 0:00 [cat] <defunct> root 785 0.0 0.0 7672 1196 ? S 14:17 0:00 avahi-publish -a test.local _test+ 787 0.0 0.0 26736 16288 ? Ss 14:17 0:00 /opt/nokia/test-acl/bin/ipsetmanager ... [root@test:/home/robot] # ps -lA F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 4 S 0 1 0 0 80 0 - 42905 SyS_ep ? 00:00:26 systemd 0 S 0 531 525 0 80 0 - 1455 hrtime ? 00:00:00 schedmon 4 S 0 534 1 0 80 0 - 1879 hrtime ? 00:00:00 hypertracerolcd 4 S 0 550 1 0 80 0 - 205661 core_s ? 00:00:15 python3 4 S 192 591 1 0 80 0 - 4788 SyS_ep ? 00:00:00 systemd-network ...
[root@test]$ pstree -p systemd(1)─┬─abrt-dbus(45043)─┬─{abrt-dbus}(45044) │ └─{abrt-dbus}(45046) ├─agetty(2037) ├─agetty(2039) ├─atd(1989) ├─auditd(604)─┬─audispd(19274)─┬─sedispatch(19275) │ │ └─{audispd}(19276) │ └─{auditd}(605) ├─automount(2029)─┬─{automount}(2030) │ ├─{automount}(2031) │ └─{automount}(2056) ...
[root@test]$ top -H top - 20:49:51 up 264 days, 3:07, 14 users, load average: 0.13, 0.08, 0.02 Threads: 567 total, 1 running, 565 sleeping, 0 stopped, 1 zombie %Cpu(s): 0.2 us, 0.1 sy, 0.0 ni, 99.6 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 37077464 total, 12919928 free, 2649664 used, 21507872 buff/cache KiB Swap: 1020 total, 0 free, 1020 used. 33678848 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 44644 root 20 0 12.7g 335660 21284 S 0.7 0.9 0:04.60 java 43794 root 20 0 12.7g 323332 21332 S 0.7 0.9 0:06.44 java 1959 fluentd 20 0 1382452 28436 4896 S 0.3 0.1 42:04.92 fluentd
[root@test test]# vi log.txt [1]+ Stopped vi log.txt [root@test test]# ps -lf F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 0 S root 107543 107542 0 80 0 - 6374 - 15:58 pts/0 00:00:00 -bash 0 T root 108848 107543 0 80 0 - 9126 - 15:58 pts/0 00:00:00 vi log.txt 0 R root 109559 107543 0 80 0 - 14894 - 15:58 pts/0 00:00:00 ps -lf [root@test test]#
[root@test test]# jobs [1]+ Stopped vi log.txt [root@test test]# fg %1 vi log.txt [root@test test]# jobs [1]- Stopped vi log.txt [2]+ Stopped vi abc [root@test test]# fg vi abc
[root@test]$ ./test.out Hello World ^Z [1]+ Stopped ./test.out [root@test]$ ps -lf F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 4 S root 49612 49605 0 80 0 - 28750 do_wai 00:13 pts/15 00:00:00 -bash 0 T root 49854 49612 0 80 0 - 1056 do_sig 00:14 pts/15 00:00:00 ./test.out 0 R root 49880 49612 0 80 0 - 38356 - 00:14 pts/15 00:00:00 ps -lf [root@test]$ bg %1 [1]+ ./test.out & Hello World [root@test]$ Hello World Hello World ^C [root@test]$ Hello World Hello World Hello World
[root@test]$ kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1 64) SIGRTMAX
# kill -9 %n [root@test]$ ./test.out Hello World Hello World ^Z [1]+ Stopped ./test.out [root@test]$ kill -9 %1 [1]+ Killed ./test.out # kill -9 PID [root@test]$ ./test.out Hello World ^Z [1]+ Stopped ./test.out [root@test]$ ps -lf F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 4 S root 49612 49605 0 80 0 - 28750 do_wai 00:13 pts/15 00:00:00 -bash 0 T root 50944 49612 0 80 0 - 1056 do_sig 00:28 pts/15 00:00:00 ./test.out 0 R root 50950 49612 0 80 0 - 38356 - 00:28 pts/15 00:00:00 ps -lf [root@test]$ bg %1 [1]+ ./test.out & Hello World [root@test]$ Hello World Hello World [1]+ Killed ./test.out [root@tu-qiaolin-683ci-1 ~]$ kill -9 50944 # exec at another tty
[root@test]$ cat test.cpp #include <stdio.h> #include <unistd.h> int main(void) { int i = 0; for(i==0;i<20;i++) { sleep(2); printf("Hello World\n"); } } [root@test]$ gcc test.cpp -o test.out [root@test]$ nohup ./test.out & [1] 50772 [root@test]$ nohup: ignoring input and appending output to ‘nohup.out’ [root@test]$ ps -lf F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 4 S root 45024 45018 0 80 0 - 28752 do_wai 20:39 pts/15 00:00:00 -bash 0 S root 50772 45024 0 80 0 - 1056 hrtime 21:41 pts/15 00:00:00 ./test.out 0 R root 50777 45024 0 80 0 - 38356 - 21:41 pts/15 00:00:00 ps -lf [root@test]$ exit logout ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Session stopped Last login: Thu Apr 23 23:48:09 2020 from 10.140.119.177 [root@tu-qiaolin-683ci-1 ~]$ ps -lA | grep 50772 0 S 0 50772 1 0 80 0 - 1056 hrtime ? 00:00:00 test.out [root@tu-qiaolin-683ci-1 ~]$ cat test/nohup.out Hello World Hello World Hello World ... [root@tu-qiaolin-683ci-1 ~]$
原文:https://www.cnblogs.com/xingzheanan/p/12776204.html