顯示具有 xargs 標籤的文章。 顯示所有文章
顯示具有 xargs 標籤的文章。 顯示所有文章

星期三, 7月 24, 2019

How to check and modify pids.max of user

1. find out the cgroup of the user

#echo $$|xargs -I '$' cat '/proc/$/cgroup'


/user.slice/user-1000.slice is the cgroup of the user

2. check the pids.max (TasksMax) setting for the user
(1) method 1:
#cgget -a /user.slice/user-1000.slice


(2) method 2:
#cat /sys/fs/cgroup/pids/user.slice/user-1000.slice/pids*

3. modify the pids.max
# systemctl set-property user-1000.slice TasksMax=512

4. verify (using python script)

import time
import threading

def worker():
    while True:
        time.sleep(1000)
        

threads = []
num_worker_threads = 19000
for i in range(num_worker_threads):
    t = threading.Thread(target=worker)
    try:
        t.start()
        threads.append(t)
        print(i)
    except:
        print("EX")
        time.sleep(2000)

for t in threads:
    t.join()
python script:
https://zhuanlan.zhihu.com/p/29192624

cgroup information:
https://access.redhat.com/documentation/zh-tw/red_hat_enterprise_linux/6/html/resource_management_guide/sec-obtaining_information_about_control_groups

xargs:
https://superuser.com/questions/401614/inserting-string-from-xargs-into-another-string




星期五, 4月 27, 2018

alias 無法使用多個指令串接解決方法

因為練習Docker, 想要把以下指令串寫成一個alias 命令來一次刪除所有的container
docker ps -a|awk '{print $1}'|grep -v CONTAINER|xargs -n 1 docker rm
但發現bash會認為語法不對, 在stackoverflow 發現以下解法, 將其寫成function (.bashrc)

docrmall() {
docker ps -a|awk '{print $1}'|grep -v CONTAINER|xargs -n 1 docker rm
}

以後只要呼叫 docrmall就可以了!

Syntax error when trying to pipe multiple commands in an alias definition

***
xargs -n 1 : 代表一次用一個值傳給後面的命令當輸入值

Linux 系統 xargs 指令範例與教學


*** update: 發現另外方式更快, 主要是 -q 這個選項可以只輸出id, 不需再去grep

(1) docker rm -f  $(docker ps -aq)
或是
(2) docker ps -aq|xargs docker rm

***

$(    )   --->  取得( ) 內的指令輸出內容

星期三, 4月 12, 2017

How to find out all used ports for the specified process in Linux and AIX


1. For Linux:
    It's easy to use the following command:
    #netstat -tupln|grep pid_of_your_process

2. For AIX:
    You must combine several commands:
    #netstat -Aan|grep LISTEN|awk '{print $1}'|xargs -i rmsock {} tcpcb > a.txt
    #netstat -Aan|grep LISTEN|awk '{print $5"\t\t"}' > b.txt
    #paste b.txt a.txt > c.txt
    #grep pid_of_your_process c.txt

*** xargs -i can use the output of previous command to replace the {} as the argument of the next command.