Lua有两种执行系统命令的方法:os.execute, io.popen

os.execute 返回的是命令执行的状态,一共返回3个值。
第一个值是truenil, true表示命令成功执行完,否则返回nil
第二个值是exit时,表示正常终止,第三个值表示退出的状态码。
第二个值是signal时,表示信号终止,第三个值表示终止的信号。

例如

> os.execute("pwd")
true exit 0
> os.execute("pwdx")
nil exit 127

io.popen 启动一个新进程执行命令,并返回一个文件句柄,可以使用该文件句柄读取返回的数据。
例如,或通过这个方法获得文件列表

local f = io.popen("ls")
print(f:read("*a")

使用table.sort时,碰到一个错误:invalid order function for sorting
原因是table.sort的比较函数返回的类型不是boolean

正确使用table.sort的方法:

-- 按数字大小降序排序
local t = { 1, 10, 8, 7}
table.sort(t, function (a, b)
    return a - b > 0
end)

-- 按数字大小升序排序
table.sort(t, function (a, b)
    return a - b < 0
end)

删除本地分支

# 删除一个已经合并的分支
git branch -d 分支名
git branch --delete 分支名

# 强制删除一个未合并的分支
git branch -D 分支名
git branch -delete --force 分支名

删除远程分支

git push origin --delete 分支名

通过top -p mysqlpid -H 可以找到thread_os_id ->

                    通过thread_os_id 和  performance_schema.threads 找到thread_id ->
                     通过thread_id和performance_schema.events_statements_current 找到sql语句

[root@node2 ~]# ps -ef | grep -i mysql
mysql 2296 1211 18 14:17 ? 00:03:46 /home/db/mysql/product/bin/mysqld --basedir=/home/db/mysql/product --datadir=/mysqldata/data --plugin-dir=/home/db/mysql/product/lib/plugin --user=mysql --log-error=/mysqldata/logs/mysql_error.log --pid-file=/mysqldata/data/mysqld.pid --socket=/home/db/mysql/product/mysql.sock --port=13306

[root@node2 ~]# top -p 2296 -H
top - 14:59:55 up 42 min, 4 users, load average: 0.41, 0.81, 1.39
Threads: 67 total, 2 running, 65 sleeping, 0 stopped, 0 zombie
%Cpu(s): 94.7 us, 4.7 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 0.7 si, 0.0 st
KiB Mem : 2238208 total, 77696 free, 943520 used, 1216992 buff/cache
KiB Swap: 2621436 total, 2621436 free, 0 used. 1139404 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAN
2966 mysql 20 0 6212608 868916 30128 R 97.3 38.8 11:46.51 mysqld
2460 mysql 20 0 6212608 868916 30128 R 0.3 38.8 0:09.28 mysqld
2296 mysql 20 0 6212608 868916 30128 S 0.0 38.8 0:00.79 mysqld

系统PID=2966 占用CPU 97%
通过performance_schema.threads.thread_os_id=2966可以找到thread_id,processlist_id ;

root@localhost 15:03:34 [performance_schema]>select thread_id,name ,PROCESSLIST_ID,THREAD_OS_ID from threads where thread_os_id = 2966 ;
thread_idnamePROCESSLIST_IDTHREAD_OS_ID
78thread/sql/one_connection102966

+-----------+---------------------------+----------------+--------------+

通过performance_schema.events_statements_current.thread_id = 78 可以找到当前占用cpu的SQL:

root@localhost 15:07:37 [performance_schema]>select DIGEST_TEXT from performance_schema.events_statements_current where thread_id = 78 ;
DIGEST_TEXT
SELECT * FROM t AS t1 , t AS t2 , t AS t3 , t AS t4

DIGEST_TEXT 的长度由变量max_digest_length控制:

root@localhost 16:08:01 [performance_schema]>show variables like 'max_digest_length' ;
Variable_nameValue
max_digest_length1024