http {
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/dash
/bin/bash
/bin/rbash
/bin/zsh
/usr/bin/zsh
$ ps $$
PID TTY STAT TIME COMMAND
7356 pts/21 Ss 0:01 -zsh
$ echo $SHELL
/usr/bin/zsh
chsh -s $(which zsh)
reboot
临时切换到 bash。
# huangjian @ huangjian-ThinkPad-T470p in ~ [17:20:31]
$ bash
huangjian@huangjian-ThinkPad-T470p:~$ exit
exit
# huangjian @ huangjian-ThinkPad-T470p in ~ [17:20:36]
$
https://bash.cyberciti.biz/guide/Sending_signal_to_Processes
The default signal for kill is TERM. To list available signals, enter:
kill -l
Sample outputs:
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
The kill command can send all of the above signals to commands and process. However, commands only give response if they are programmed to recognize those signals. Particularly useful signals include:
To send a kill signal to PID # 1234 use:
kill -9 1234
OR
kill -KILL 1234
OR
kill -SIGKILL 1234
killall sends a signal to all processes running any of the specified commands . If no signal name is specified, SIGTERM is sent. To terminate all firefox process (child and parent), enter:
killall processName
killall firefox-bin
To send a KILL signal to firefox, enter:
killall -s SIGKILL firefox-bin
The pkill command is another command with additional options to kill process by its name, user name, group name, terminal, UID, EUID, and GID. It will send the specified signal (by default SIGTERM) to each process instead of listing them on stdout. To send a kill signal to php-cgi process, enter:
pkill -KILL php-cgi
The above example will kill all users php-cgi process. However, -u option will kill only processes whose effective user ID is set to vivek:
pkill -KILL -u vivek php-cgi
Make sshd reread its configuration file, enter:
pkill -HUP sshd
Event loop that drives Tokio I/O resources.
This module contains Reactor, which is the event loop that drives all Tokio I/O resources. It is the reactor’s job to receive events from the operating system (epoll, kqueue, IOCP, etc…) and forward them to waiting tasks. It is the bridge between operating system and the futures model.
When using Tokio, all operations are asynchronous and represented by futures. These futures, representing the application logic, are scheduled by an executor (see runtime model for more details). Executors wait for notifications before scheduling the future for execution time, i.e., nothing happens until an event is received indicating that the task can make progress.
The reactor receives events from the operating system and notifies the executor.
Let’s start with a basic example, establishing a TCP connection.
use tokio::prelude::*;
use tokio::net::TcpStream;
let addr = "93.184.216.34:9243".parse().unwrap();
let connect_future = TcpStream::connect(&addr);
let task = connect_future
.and_then(|socket| {
println!("successfully connected");
Ok(())
})
.map_err(|e| println!("failed to connect; err={:?}", e));
tokio::run(task);
Establishing a TCP connection usually cannot be completed immediately. TcpStream::connect does not block the current thread. Instead, it returns a future that resolves once the TCP connection has been established. The connect future itself has no way of knowing when the TCP connection has been established.
Before returning the future, TcpStream::connect registers the socket with a reactor. This registration process, handled by Registration, is what links the TcpStream with the Reactor instance. At this point, the reactor starts listening for connection events from the operating system for that socket.
Once the connect future is passed to tokio::run, it is spawned onto a thread pool. The thread pool waits until it is notified that the connection has completed.
When the TCP connection is established, the reactor receives an event from the operating system. It then notifies the thread pool, telling it that the connect future can complete. At this point, the thread pool will schedule the task to run on one of its worker threads. This results in the and_then closure to get executed.
// T 是一个泛型
// PartialOrd 是一个 trait
// Copy 也是一个 trait
// <T: PartialOrd + Copy> 意思是:实现了 PartialOrd 和 Copy 这两个 trait 的泛型。
// 也就是说传递到函数 largest 中的 T 必须同时实现了接口 PartialOrd 和 Copy。
fn largest<T: PartialOrd + Copy>(list: &[T]) -> T {
let mut largest = list[0];
for &item in list.iter() {
if item > largest {
largest = item;
}
}
largest
}
// 和 largest 函数是一样的, where 只是语法糖
fn largest1<T>(list: &[T]) -> T
where
T: PartialOrd + Copy,
{
let mut largest = list[0];
for &item in list.iter() {
if item > largest {
largest = item;
}
}
largest
}
fn main() {
let number_list = vec![34, 50, 25, 100, 65];
let result = largest(&number_list);
println!("The largest number is {}", result);
let char_list = vec!['y', 'm', 'a', 'q'];
let result = largest1(&char_list);
println!("The largest char is {}", result);
}