• 一亩三分地


    Linux应用

    1.如何快速找出当前目录下最晚被修改过的文件?

    ls -lt | head -1
    

    2.已知某个进程的pid是6666,如何找到它当前打开了哪些文件?

    lsof -p 6666
    

    3.发现端口8001被占用,如何找出是哪个进程占用了该端口?

    netstat -lnp|grep 8001
    #或
    lsof -i:8001
    

    4.假设有进程P持续向文件F写入数据,此时把文件F删除,进程P的写入会失败吗?磁盘占用是否会持续增加?为什么?

    不会,会增加,	删除的只是文件的目录链接,进程仍然在执行
    

    5.给你一个文件,每行一个ip,如何用shell快速找到出现次数最多的ip?

    假设文件名为 t1.txt
    cat t1.txt | awk '{print$2}'|sort|uniq -c |sort -n-r|head -n 1
    

    数据处理

    1.数据库中存在如下数据,记录了每个人每一门课程的成绩以及该课程其他人最高得分。写出语句计算每个人得分最高(score)的两门课,分数相同时任意返回一个皆可。

    如下原始数据:

    Name Class Score MaxScore
    语文 80 100
    英语 80 120
    数学 100 130
    语文 100 100
    英语 80 120
    数学 130 130

    预期输出:

    Name Class Score MaxScore
    数学 100 130
    语文 80 100
    数学 130 130
    语文 100 100
    • 假设数据存在mysql中,请写出sql语句
    select * from (select * from 表名 order by Score desc limit 2) group by Name
    
    • 假设数据存在hive中,请写出sql语句
    select * from (select *,row_number() over (partition by Name order by Score desc) as row_num from 表名) as 表名 where row_num<=2
    
    • 假设数据存在elasticsearch中,请写出查询DSL
    ......
    

    Python

    1.为runner.py实现一个函数,检测是否有其他的runner.py进程在正在执行

    import time 
    import os 
    import psutil
    def write():
        pid = os.getpid()
        with open('pid.txt','w') as f:
            f.write(str(pid))
    def read():
        if os.path.exists('pad.txt'):
            with open('pid.txt','r') as f:
                pid = f.read()
                return pid
        else:
            return '0'
    if __name__ == '__main__':
        pid = int(read())
        if pid:
            running_pids = psutil.pids()
            if pid in running_pids:
                print('还有其他running.py进程在执行')
            else:
                write()
                print('没有其他的running.py进程在执行')
                time.sleep(10)
        else:
            write()
            print('没有其他的running.py进程在执行')
            time.sleep(10)
    

    2.实现一段代码,从文件中读取数据,输入一个日期,返回对应日期当天能够确认收入的金额

    lat = []
    with open(r"D:untitled一亩田试题	ext","r",encoding="utf-8") as f:
        for line in f.readlines():
            lat.append(list(map(int,line.split(','))))
    num = input('请输入数字:')
    count = 0
    for a in lat:
        if a[2]<=int(num)<=a[-1]:
            count += 1
    print(f'今日返回{count*10}元')
    
    • 补充问题:如果金额不能整除,我们一般会在权益的最后一天做特殊处理,让金额保持一致。(例如:100元的权益有效期30天,前29天每天计算333分,最后一天计算343分)。如果需要考虑这种情况,代码应该怎么实现?
    lat = []
    # 将文本内容封装到lat中
    with open(r"D:untitled190705试题	ext","r",encoding="utf-8") as f:
        for line in f.readlines():
            lat.append(list(map(int,line.split(','))))
        print(lat)
    num = input('请输入数字:')
    count = 0
    money = 0
    for a in lat:
        # 判断是否整除
        if a[1] % 30 == 0:
            # 判断会员权益是否到期
            if a[2] <= int(num) <= a[-1]:
                count += 1
        else:
            # 金额取余
            b = a[1]%30
            # 将余数剔除,加入到最后一天中
            c = (a[1]-b)/30
            # 判断会员权益是否到期
            if a[2] <= int(num) < a[-1]:
                money += c
            # 判断是否是权益的最后一天
            elif int(num) == a[-1]:
                money = c+b
    print(f'今日返会{count*1000+money}分')
    

    Golang

    抱歉,暂时没有接触过这门语言
    
  • 相关阅读:
    存储过程
    数据库中的锁
    数据库事务
    三大范式
    IOC(一)
    rabbitmq部署
    配置SQLServer2012,允许远程连接
    6种常见的Git错误以及解决的办法
    灵活使用Win+R快捷键提高工作效率
    sql 创建视图常用的几种sql函数
  • 原文地址:https://www.cnblogs.com/lvtaohome/p/12643467.html
Copyright © 2020-2023  润新知