wenmo8 发布的文章

1、pgrep是什么?

pgrep是一个命令行程序,可以根据输入给定的条件查找正在运行的程序的进程ID

它可以是完整或部分进程名称,运行该进程的用户或其他属性

 

语法:

1
pgrep(选项)(参数)

 

选项:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
-d, --delimiter <string>  specify output delimiter
 -l, --list-name           list PID and process name
 -a, --list-full           list PID and full command line
 -v, --inverse             negates the matching
 -w, --lightweight         list all TID
 -c, --count               count of matching processes
 -f, --full                use full process name to match
 -g, --pgroup <PGID,...>   match listed process group IDs
 -G, --group <GID,...>     match real group IDs
 -n, --newest              select most recently started
 -o, --oldest              select least recently started
 -P, --parent <PPID,...>   match only child processes of the given parent
 -s, --session <SID,...>   match session IDs
 -t, --terminal <tty,...>  match by controlling terminal
 -u, --euid <ID,...>       match by effective IDs
 -U, --uid <ID,...>        match by real IDs
 -x, --exact               match exactly with the command name
 -F, --pidfile <file>      read PIDs from file
 -L, --logpidfile          fail if PID file is not locked
 --ns <PID>                match the processes that belong to the same

   

参数:

进程名称:指定要查找的进程名称,同时也支持类似grep指令中的匹配模式

 

例子:

-f 选项

# pgrep -f clickhouse-server 
7237672378

 

-l 选项

# pgrep -f clickhouse-server -l72376 clckhouse-watch72378 clickhouse-serv

 

-d 选项

# pgrep -f clickhouse-server -l -d ' '72376 clckhouse-watch 72378 clickhouse-serv

 

-u 选项

复制代码

# 组合模式,查找root或者j-huangxianghai-jk下的进程
pgrep -u root,j-huangxianghai-jk -l201341 kdmflush201343 bioset201488 jbd2/dm-4-8201489 ext4-rsv-conver

# 打印在用户j-huangxianghai-jk用户下且名称中包含sshd
pgrep -u j-huangxianghai-jk sshd -l

复制代码

 

特别说明:

1)pgrep相当于# ps -eo pid,cmd | awk '{print $1,$2}' | grep clickhouse-server

72378 /usr/bin/clickhouse-server

 

2)pgrep查找的是程序名,不包括其参数

复制代码

[root@ck21 j-huangxianghai-jk]# ps aux|grep sshd
root       1511  0.0  0.0 106056  4176 ? Ss   Oct18   0:00 /usr/sbin/sshd -D
root      59820  0.0  0.0 145760  5300 ? Ss   13:59   0:00 sshd: j-huangxianghai-jk [priv]
j-huang+  59828  0.0  0.0 147844  3048 ? S    13:59   0:00 sshd: j-huangxianghai-jk@pts/0root      60147  0.0  0.0 145760  5296 ? Ss   14:00   0:00 sshd: j-huangxianghai-jk [priv]
[root@ck21 j-huangxianghai-jk]# pgrep j-huangxianghai-jk
[root@ck21 j-huangxianghai-jk]# pgrep sshd1511598205982860147

复制代码


1、拷贝项目包到Linux后安装virtualenv
pip install virtualenv
2、创建项独立的env目录,由于我这里的是venv,所有创建的是venv
# python -m virtualenv venv
  No LICENSE.txt / LICENSE found in sourceNew python executable in /opt/oppython/autoInstallNn/venv/bin/python
Installing setuptools, pip, wheel...done.
3、加载独立环境
# source venv/bin/activate不是加载Scripts目录下的activate


使用 Bash 脚本自动执行各种任务。掌握基础知识并开始您的 Bash 脚本之旅。

Bash 脚本可用于自动化任务,您会发现它们非常适合构建简单的命令行应用程序。Bash shell 解释 Bash 脚本,因此您无需安装任何依赖项即可编写和运行它们。Bash 脚本也是可移植的,因为大多数基于 Unix 的操作系统都使用相同的 shell 解释器。
每个开发人员都必须具备 Bash 脚本知识,尤其是在使用基于 Unix 的系统时。

Bash 中的变量

Bash 变量区分大小写。要声明变量,请使用等号(=),名称在左侧,值在右侧:

STATE=LinuxMi

此声明分配给STATE的值是一个单词。如果您的值中需要空格,请在其周围使用引号:

STATE="Ubuntu Linux"

您需要使用美元符号($)前缀来引用其他变量或语句中的变量:

STATE=LinuxMiLOCATION="My Site is $STATE"

在 Bash 中打印值

有几种方法可以在 Bash 中打印变量。您可以使用echo命令进行基本输出,或使用 C 风格的printf命令进行字符串格式化。

STATE=LinuxMiLOCATION="My Site is $STATE"echo $LOCATION

声明STATE变量后,此脚本通过引用 STATE 来定义LOCATION 。如果 then 使用 echo 打印 LOCATION 变量的最终值。
图片
printf关键字允许您使用格式化动词来输出数据。字符串格式化动词类似于 C 和 Go 中的动词,但动词有限。

动词功能性
%C打印单个字符
%o打印八进制
%s打印字符串,独立于大小写
%X打印小写十六进制
%X打印大写十六进制
%d打印整数
%e以小写形式打印科学概念浮点数
%E以大写形式打印科学概念浮点数
%F打印浮点数
%%打印一个百分比符号。

这是一个使用带有print关键字的动词的示例。

STATE=LinuxMi.comprintf "My Site is %s" $STATE

图片

printf函数将在%s动词的位置替换STATE变量,输出将是“My Location is Lagos”。

Bash 中的注释

您可以在 Bash 中使用井号或井号 ( # ) 符号进行注释。shell 会自动忽略注释。




#!/bin/bash# STATE=LinuxMi.com# LOCATION="My Site is $STATE"


没有多行注释。大多数 IDE 和文本编辑器允许您使用 Ctrl/Command + 正斜杠 (/) 快捷方式进行注释。您应该能够使用快捷方式创建多个单行注释。

在 Bash 中接收用户输入

与许多其他编程语言一样,您可以在 Bash 中接收用户输入,以使您的程序/脚本更具交互性。您可以使用read命令来请求用户的输入。


read response


在这种情况下,response变量将保存用户在交付时的输入。




echo "What do you want ?: "read responseecho $response


在上面的示例中,用户输入请求将位于新行上。

图片

您可以将-n标志添加到echo print 语句以保留用户输入输入的行。

echo -n "What do you want."read responseecho $response

图片

在 Bash 中声明数组

Bash中的数组就像大多数语言一样。您可以通过在括号中指定元素来在 Bash 中声明一个数组变量。


Countries=('Ubuntu' 'Debian' 'CentOS', "openSUSE", "Linuxmi.com")


通过引用变量名访问数组将获取第一个元素。您可以使用星号作为索引来访问整个数组。


echo ${Countries[*]}


您还可以指定数组的索引来访问特定元素。数组的索引从零开始。

echo "${Countries[4]}"

图片

Bash 中的条件语句

Bash 为程序中的决策提供条件。

这是 Bash 中 if-else 语句的剖析。您必须使用分号来指定条件的结束。








if [[ condition ]]; then   echo statement1elif [[condition ]]; then   echo statement2else [[condition ]]; then   echo statement3fi


您必须以fi关键字结束每个if语句。








if [ 1 == 2 ]; then   echo one elif [ 2 == 3 ]; then #else-if   echo twoelse [ 4 > 3 ];    echo "correct, 3"fi


您可以使用case关键字在 Bash 程序中使用 case 语句。您必须指定模式,然后在语句之前加上括号。
















NAME=LinuxMicase $NAME in  "Debian") # 模式    echo "Debian是目前世界最大的非商业性Linux发行版之一" # 声明    ;; # case 结束  "LinuxMi" | "Ubuntu")    echo  "openSUSE"    ;;  "CentOS" | "oracle linux")    echo  "linux"    ;;  *) # 默认模式    echo "linuxmi.com" # 默认声明    ;;esac # case声明结束


您可以使用星号 (*) 符号作为模式定义默认大小写。case 语句必须以esac关键字结尾。

Bash 中的循环

根据您的需要,您可以使用 while 循环、范围 for 循环或 C 风格的 for 循环进行重复操作。

这是 C 风格的 for 循环的示例。For 循环必须以done关键字结尾,并且您必须以分号后跟do关键字结束 for 语句。




for ((a = 0 ; a < 10 ; a+2)); do  echo $adone


对于处理文件和许多其他操作,for 循环的范围很方便。您需要将in关键字与范围 for 循环一起使用。




for i in {1..7}; do    echo $1done


图片

这是一个简单的无限循环,用于演示 Bash while循环的实际作用。






linuxmi=1while [ 1 -le 5 ] # while 1 < 5do  echo $linuxmidone


条件语句中的-le是小于的二元运算符。

Bash 中的函数

在 Bash 中声明函数不需要关键字。您可以使用名称声明函数,然后在函数体之前加上括号。





print_working_directory() {  echo $PWD  #从脚本调用PWD命令}echo "当前的目录是 $(print_working_directory)"


图片

函数可以在 Bash 中返回变量。您所需要的只是return关键字。




print_working_directory() {  return $PWD}


print_working_directory函数返回文件的工作目录。

你可以用其他语言编写 Shell 脚本

Bash 并不是您可以用来与操作系统的 shell 交互或构建命令行应用程序的唯一语言。您可以使用许多其他语言,例如 Go、Python、Ruby 和 Rust。

许多操作系统都预装了 Python3,而 Python 是一种流行的语言。如果您需要比 Bash 脚本提供的更多功能,请考虑使用 Python。


一、前言                                  

  以下场景往往由于事件频繁被触发,因而频繁执行DOM操作、资源加载等重行为,导致UI停顿甚至浏览器崩溃。

  1. window对象的resize、scroll事件

  2. 拖拽时的mousemove事件

  3. 射击游戏中的mousedown、keydown事件

  4. 文字输入、自动完成的keyup事件

  实际上对于window的resize事件,实际需求大多为停止改变大小n毫秒后执行后续处理;而其他事件大多的需求是以一定的频率执行后续处理。针对这两种需求就出现了debounce和throttle两种解决办法。本篇暂且只讨论debounce方式

二、什么是debounce                            

   1. 定义

  如果用手指一直按住一个弹簧,它将不会弹起直到你松手为止。

      也就是说当调用动作n毫秒后,才会执行该动作,若在这n毫秒内又调用此动作则将重新计算执行时间。

    方法定义如下

复制代码

1 /**2 * 空闲控制 返回函数连续调用时,空闲时间必须大于或等于 idle,action 才会执行3 * @param fn   {Function}    相关执行函数4 * @param delay {Number}  延迟时间,也就是阈值,单位是毫秒5 * @return {function}    返回一个“去弹跳”了的函数6 */7 debounce(fn,delay)

复制代码

2. 简单实现

复制代码

 1 /** 2   * 3   * @param fn {Function}   实际要执行的函数 4   * @param delay {Number}  延迟时间,也就是阈值,单位是毫秒(ms) 5   * 6   * @return {Function}     返回一个“去弹跳”了的函数 7   */ 8   function debounce(fn, delay) { 9 10     // 定时器,用来 setTimeout11     var timer12 13     // 返回一个函数,这个函数会在一个时间区间结束后的 delay 毫秒时执行 fn 函数14     return function () {15 16       // 保存函数调用时的上下文和参数,传递给 fn17       var context = this18       var args = arguments19 20       // 每次这个返回的函数被调用,就清除定时器,以保证不执行 fn21       clearTimeout(timer)22 23       // 当返回的函数被最后一次调用后(也就是用户停止了某个连续的操作),24       // 再过 delay 毫秒就执行 fn25       timer = setTimeout(function () {26         fn.apply(context, args)27       }, delay)28     }29   }

复制代码

 

下面展示效果

 一般代码

一般效果

加上去抖动逻辑后代码

去抖动后效果


django wsgi python中wsgi模块的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

前言

django wsgi python有个自带的wsgi模块 可以写自定义web框架 用wsgi在内部创建socket对象就可以了 自己只写处理函数就可以了

django只是web框架 他也不负责写socket django 依赖wsgi接口创建socket

wsgi是一套规则 是一套接口

按照wsgi规则写 以后想封装socket 在内部封装socket就可以了 我只要遵循规则 把wsgi模块一导入 我就可以使用wsgi写的socket了

遵循wsg socketi接口有哪些

这些模块已经创建好socket了

server_names = {
  'cgi': CGIServer,
  'flup': FlupFCGIServer,
  'wsgiref': WSGIRefServer,
  'waitress': WaitressServer,
  'cherrypy': CherryPyServer,
  'paste': PasteServer,
  'fapws3': FapwsServer,
  'tornado': TornadoServer,
  'gae': AppEngineServer,
  'twisted': TwistedServer,
  'diesel': DieselServer,
  'meinheld': MeinheldServer,
  'gunicorn': GunicornServer,
  'eventlet': EventletServer,
  'gevent': GeventServer,
  'geventSocketIO':GeventSocketIOServer,
  'rocket': RocketServer,
  'bjoern' : BjoernServer,
  'auto': AutoServer,
}

django 依赖wsgi模块socket django都会导入 python内部的wsgi模块

django 项目有个wsgi.py 文件

import osfrom django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
application = get_wsgi_application()