1.Linux相關

1.查看家目錄下a.log日誌文件的最後200行

tail -n 200 ~/a.log

2.查看8080端口是否被佔用

lsof -i :8080
lsof=list open files
-i :8080表示查看所有使用8080端口的進程

3.查看當前目錄及子目錄下的所有文件(超過3天的)

find . -type f -mtime +3
find是查找命令
.是當前目錄
-type f只查找文件
-mtime +3修改時間超過3天(+表示早於)

4.兩台機器傳遞文件命令

從本地傳到遠程
scp /home/user/file.txt root@192.168.1.10:/root/
從遠程下載到本地
scp root@192.168.1.10:/root/file.txt /home/user/
傳整個目錄
scp -r /home/user/project root@192.168.1.10:/root/
指定端口
scp -P 2222 file.txt root@192.168.1.10:/root/

5.如果現在有一個進程佔用了80端口號,用什麼指令找到它然後殺掉該進程

sudo lsof -i :80通過這個指令查看80端口下的進程PID
studo kill -9 10247這個進程的PID為10247

6.查看file.txt文件的內容

cat file.txt

7.linux編輯文件的命令,怎麼進入編輯,怎麼跳轉最後一行,怎麼跳轉指定行

用vi打開文件
vi filename
輸入以下任意鍵進入編輯模式
i在光標前插入
a在光標後插入
o在下一行新建一行並進入編輯
I在當前行首插入
A在當前行末進行插入
:w保存
:q退出
:wq保存並退出
G跳轉到文件末尾
gg跳轉到文件開頭
:行號跳轉到指定行號

8.linux下查看進程號

ps查看當前終端下正在運行的進程
ps -u 用户名  查看當前用户的進程
ps -ef查看所有進程
ps -ef | grep nginx查找特定進程號
top實時查看進程

9.一個文件app.log,篩選出包含error的行並保存到另一個文件中

grep用來在文件中查找指定的字符串或匹配模式,並把包含內容的行打印出來
grep [選項] “搜索內容” 文件名
grep -i忽略大小寫
grep -n 顯示行號
grep "error" app.log > error.log

2.SQL相關

1.student表(student_id,name,year)score表(score_id,student_id,score)如何查詢學生成績

select student.student_id,student.name,score.score
from student這裏from指定主數據來源表,然後通過JOIN再把其他表連起來
join score
on student.student_id=score.student_id這裏的ON用來指定兩張表之間的連接條件(匹配關係)

另外寫法
select 
s.student_id,
s.name,
sc.score
from student s這裏就是把student表直接起了個s的別名
join score sc on s.student_id=sc.student_id

進一步篩選不要2023年和2024年的學生

select s.student_id,s.name,sc.score
from student s
join score sc on s.student_id=sc.student_id
where s.year not in (2023,2024);

2.刪除一個表

drop table 表名

3.查找成績為前三的同學的姓名(有兩個表student和score)

select s.name,sc.score
from student s
join score sc on s.student_id=sc.student_id
order by sc.score desc
limit 3

如果只有一個表(student)

select name,score
from student
order by score desc
limit 3;

4.Redis和Mysql誰的讀寫速度快,為什麼

Redis,直接在內存中進行讀寫,無需磁盤I/O,低層採用了高效的數據結構:哈希表,鏈表,字符串,集合,有序集合

Mysql每次查詢/更新都可能涉及磁盤讀寫,低層使用B+樹、磁盤頁存儲結構,需要磁盤尋址、索引查找

5.有一個學生選課表,包含字段:學生ID(studentid)、課程id(course id)、和課程得分(score)

如何查詢至少選修兩門課程的學生的學生ID

select student_id
from student_course
group by student_id
having count(distinct course_id)>=2;

6.數據庫有10行一樣的數據,刪除9行,只留下1行(學生表student(id name number))

表student裏有很多相同的name和number,只想保留id最小的那條,其他都刪掉
delete fro
here id not in(
    select id from(
        select id,
            row_number()over(partition by name, number order by id) as rn
        from student
    )t
    where t.rn=1
);
row_number()給每組重複記錄編號
partition by name,number表示以這些字段為重複判斷條件
where rn=1保留第一條
外層的delete刪除編號大於1的重複行
delete form student
where id not in(子查詢)表示子查詢選出來的數據我們要保留,其他都刪掉

7.學生表(name,id,number)和成績表(name,id,score),查張三,電話,成績

select s.name,s.number,sc.score
from student s
join score sc on s.id=sc.id
where s.name="張三"

8.一個表data(id name age city)篩選來自北京的用户名;查詢每個城市的平均年齡並降序排列

select name 
from data
where city="北京"


select city,avg(age) as a
from data
group by city
order by a desc

3.算法題

1.將兩個無序數組拼接成一個有序數組

public class Merge{
    public static void main (String args[]){
        Integer [] nums1={1,4,3,7};
        Integer [] nums2={1,0,3,6,3};
        ArrayList<Integer>list=new ArrayList<>();
        list.addAll(Arrays.aslist(nums1));
        list.addAll(Arrays.aslist(nums2));
        Collections.sort(list);
        System.out.println(list);
    }
}

2.翻轉字符串

public class reverse2 {
    public static void main(String[] args) {
        String s="helloworld";
        List <Character> list=new ArrayList<>();
        for(char c:s,toCharArray()){
            list.add(c);
        }
        Collections.reverse(list);
        StringBuilder sb=new StringBuilder();
        for(char c:list){
            sb.append(c);
        }
        String str=new String(sb);
        System.out.println(str);
    }
}

3.無重複字符的最長子串(返回的是長度)

public class solution{
    public static int Longest(String s){
           int right=0;
           int max=0;
           Set<Charcter> occ=new HashSet<Character>();
           for(int i=0;i<s.length();i++){
                if(i!=0){
                  occ.remove(s.charAt(i-1));
                }
                while(right<s.length() && !occ.contains(s.charAt(right)){
                    occ.add(s.charAt(right));
                    right++;
                 }
                max=Math.max(right-i+1,max);

            }
            return max;
     }
}

(返回的是子串)

public class NotSmaeLongest {
    public static String Longest(String s){
        int right=-1;
        int ans=0;
        int best_start = 0;
        Set<Character>set=new HashSet<>();
        for ( int left = 0; left <s.length() ; left++) {
            if(left!=0) {
                set.remove(s.charAt(left - 1));
            }
            while(right+1<s.length()&&!set.contains(s.charAt(right+1))){
                set.add(s.charAt(right+1));
                right++;
            }
            int current=right-left+1;
            
            if(current>ans){
                ans=current;
                best_start=left;
            }

        }
        return s.substring(best_start,best_start+ans);
    }
}

4.反轉字符串裏的單詞

class Solution {
    public String reverseWords(String s) {
        s.trim();
        List<String>list=Arrays.asList(s.split("\\s+"));
        Collections.reverse(list);
        return String.join(" ",list);
    }
}

5.快排

6.給定一個數組,將所有重複元素刪除,只保留每個元素出現一次的元素,時間複雜度O(n)

import java.util.*;

public class Delete_repeat {
    public static String find(int[] nums) {
        Set<Integer> set = new LinkedHashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        return set.toString();
    }

    public static void main(String[] args) {
        int[] a = {1,1,2,2,3,3,4,4,5,5,6,6,7};
        System.out.println(find(a)); // [1, 2, 3, 4, 5, 6, 7]
    }
}

7.判斷環形鏈表(兩種方法:1.快慢指針,時間複雜度O(n),空間複雜度O(1)2.哈希表,時間複雜度O(n),空間複雜度O(n)

class ListNode2{
    int val;
    ListNode2 next;
    ListNode2(int x){
        val=x;
        next=null;
    }
}
public class CircleList2 {
    public static boolean Circle(ListNode head){
        if(head==null||head.next==null)return false;
        ListNode slow=head;
        ListNode fast=head.next;
        while(slow!=fast){
            if(fast==null||fast.next==null)return false;
            slow=slow.next;
            fast=fast.next.next;
        }
        return true;
    }

    public static void main(String[] args) {
        ListNode head=new ListNode(1);
        head.next=new ListNode(2);
        head.next.next=new ListNode(3);
        head.next.next.next=head.next;
        System.out.println(Circle(head));
    }

}
import java.util.HashSet;
import java.util.Set;

class ListNode{
    int val;
    ListNode next;
    ListNode(int x){val=x;next=null;}
}
public class CircleList {
    public static boolean Circle(ListNode head){
        Set<ListNode> set=new HashSet<ListNode>();
        while(head!=null){
            if(set.contains(head)){
                return true;
            }
            else{
                set.add(head);
                head=head.next;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        ListNode head=new ListNode(1);
        head.next=new ListNode(2);
        head.next.next=new ListNode(3);
        head.next.next.next= head.next;
        System.out.println(Circle(head));
    }
}

8.找到數組中的中位數,時間複雜度O(n)

9.輸入一個字符串,找出第一個不重複字符並返回索引位置,沒有則返回-1,

4.場景題

1.如何測試一個登錄頁面,寫出測試用例,從哪幾個方面進行測試

2.測試中你針對哪些模塊進行功能測試

3.電梯設計測試用例

4.怎麼測試數組和鏈表

5.計算機網絡

1.三次握手四次揮手

2.在網站輸入網址後到查看網址的過程

3.有32台主機,需要的子網掩碼要多少位

百度測試開發提前批一面面經_51CTO博客_#實習

百度測試開發提前批一面面經_51CTO博客_服務器_02

4.瀏覽器從輸入URL到頁面完全加載顯示的整個過程是什麼樣的

階段1:先對地址欄進行預處理:瀏覽器會對URL進行格式校驗與補全

階段2:DNS域名解析:將域名轉換成IP地址,因為瀏覽器無法直接通過域名找到服務器,必須先由DNS將域名解析為IP地址

階段3:建立網絡連接(TCP三次握手)如果是HTTP協議則通過TCP三次握手進行連接,如果是HTTPS協議,則在TCP三次握手之後進行加密握手(TLS/SSL),建立安全信道實現數據加密、身份認證、數據完整性校驗

階段4:發送HTTP請求

階段5:服務器處理請求

階段6:瀏覽器接收響應

階段7:瀏覽器進行渲染頁面

階段8:連接關閉(TCP四次揮手)

5.TLS/SSL加密握手過程

第一步:瀏覽器向服務器發起請求(告訴服務器我是誰,所支持的加密方式,生成一個隨機數)

第二步:服務器迴應(告訴瀏覽器選了哪種加密算法,生成隨機數,用數字證書證明自己的身份)

第三步:瀏覽器驗證服務器的證書(是否是CA機構簽發,域名是否匹匹配,證書是否過期或吊銷)

第四步:雙方生成同一個對稱加密秘鑰

第五步:雙方確認(瀏覽器用剛生成的秘鑰加密一段消息,服務器用同樣秘鑰解密)雙方驗證成功後,握手完成

第六步:安全信道建立,加密通信開始

6.GET和POST請求分別發送幾個TCP包

對於GET請求,“三次握手”3個包,“發送請求”1個包,“服務器響應”1個包或者多個,一共約5個包

對於POST請求,如果請求體較大,可能需要分開發送請求頭和請求體,通常是6個過更多個包

如果是HTTPS協議,在上面的基礎上還要加上SSL/TLS握手階段(約4-6個包)

6.操作系統

1.併發與並行

併發是交替處理多個任務的能力,並行是真正同時執行多個任務的能力