第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

作業(yè)社區(qū)

探索學習新天地,共享知識資源!

0 提交作業(yè)
0 布置作業(yè)
0 滿分作業(yè)
得分 100
學習任務

weixin_慕九州3042664 的學生作業(yè):

代碼如下: #include #include #include #include #include #include #include #include #define PATH "." #define MAGIC 0xDEAD #define SHM_SIZE 1024 static char buf[SHM_SIZE]; int main(int argc, char *argv[]) { if(argc != 3) { fprintf(stderr, "Usage: transmit \n"); exit(EXIT_FAILURE); } key_t key = ftok(PATH, MAGIC); if(key == -1) { perror("ftok()"); exit(EXIT_FAILURE); } int shmid = shmget(key, SHM_SIZE, IPC_CREAT | 0666); if(shmid == -1) { perror("shmget()"); exit(EXIT_FAILURE); } int pid = fork(); if(pid == -1) { perror("fork()"); exit(EXIT_FAILURE); } else if(pid == 0) { char *addr = shmat(shmid, NULL, 0); if(addr == (void*)-1) { perror("shmat()"); exit(EXIT_FAILURE); } FILE *fp = fopen(argv[1], "rb"); if(NULL == fp) { fprintf(stderr, "fopen() error"); exit(EXIT_FAILURE); } fseek(fp, 0, SEEK_END); int file_size = ftell(fp); if(file_size == 0) { fprintf(stderr, "file size is zero, impossible for handling"); exit(EXIT_FAILURE); } printf("read % bytes to buf\n", file_size); memcpy(buf, &file_size, sizeof(file_size)); fseek(fp, 0, SEEK_SET); fread(buf + sizeof(file_size), 1, file_size, fp); fclose(fp); memcpy(addr, buf, file_size + sizeof(file_size)); exit(0); } else { wait(NULL); char *addr = shmat(shmid, NULL, 0); if(addr == (void*)-1) { perror("shmat()"); exit(EXIT_FAILURE); } FILE *fp = fopen(argv[2], "wb"); if(NULL == fp) { fprintf(stderr, "fopen() error"); exit(EXIT_FAILURE); } int file_size = *((int *)addr); printf("file size is %d\n", file_size); memcpy(buf, addr + 4, file_size); fwrite(buf, 1, file_size, fp); fclose(fp); } int ret = shmctl(shmid, IPC_RMID, NULL); if(ret == -1) { perror("shmctl()"); exit(EXIT_FAILURE); } return 0; }

得分 100
學習任務

學無止境呀呀呀 的學生作業(yè):

#!/bin/bash # 批處理文件創(chuàng)建腳本 # 功能:根據(jù)參數(shù)創(chuàng)建指定數(shù)量的文件 # 檢查參數(shù)個數(shù) if [ $# -eq 0 ] || [ $# -gt 2 ]; then echo "錯誤: 參數(shù)個數(shù)不正確!" echo "用法: $0 [文件個數(shù)]" echo "示例: $0 log 3 # 創(chuàng)建 log_1.txt, log_2.txt, log_3.txt" echo "示例: $0 data # 創(chuàng)建 data_1.txt 到 data_5.txt(默認5個)" exit 1 fi # 獲取文件名參數(shù) filename="$1" # 根據(jù)參數(shù)個數(shù)設置文件數(shù)量 if [ $# -eq 2 ]; then # 兩個參數(shù):使用第二個參數(shù)作為文件數(shù)量 count="$2" # 驗證文件數(shù)量是否為有效數(shù)字 if ! [[ "$count" =~ ^[1-9][0-9]*$ ]]; then echo "錯誤: 文件個數(shù)必須是正整數(shù)" exit 1 fi else # 一個參數(shù):使用默認數(shù)量5 count=5 fi echo "正在創(chuàng)建 $count 個文件..." echo "文件名格式: ${filename}_X.txt" # 使用循環(huán)創(chuàng)建文件 for i in $(seq 1 $count); do # 生成文件名 new_file="${filename}_${i}.txt" # 創(chuàng)建空文件 touch "$new_file" # 顯示創(chuàng)建信息 echo "已創(chuàng)建: $new_file" done echo "完成! 共創(chuàng)建了 $count 個文件。" #!/bin/bash # 目錄統(tǒng)計腳本 # 功能:統(tǒng)計指定目錄下的普通文件和目錄文件數(shù)量(不包含隱藏文件) # 檢查參數(shù)個數(shù) if [ $# -ne 1 ]; then echo "錯誤: 參數(shù)個數(shù)不正確!" echo "用法: $0 " echo "示例: $0 /home/user/documents" exit 1 fi # 獲取目錄參數(shù) directory="$1" # 判斷參數(shù)是否為目錄 if [ ! -d "$directory" ]; then echo "錯誤: '$directory' 不是一個有效的目錄!" exit 1 fi # 檢查目錄是否可讀 if [ ! -r "$directory" ]; then echo "錯誤: 沒有權限讀取目錄 '$directory'!" exit 1 fi echo "正在統(tǒng)計目錄: $directory" echo "----------------------------------------" # 初始化計數(shù)器 file_count=0 dir_count=0 # 使用循環(huán)遍歷目錄中的所有項(不包含隱藏文件) for item in "$directory"/*; do # 檢查是否存在匹配(當目錄為空時,通配符會返回自身) if [ "$item" = "$directory/*" ]; then break fi # 統(tǒng)計普通文件 if [ -f "$item" ]; then ((file_count++)) # 統(tǒng)計目錄文件 elif [ -d "$item" ]; then ((dir_count++)) fi done # 顯示統(tǒng)計結果 echo "統(tǒng)計結果:" echo "普通文件數(shù)量: $file_count" echo "目錄文件數(shù)量: $dir_count" echo "總計: $((file_count + dir_count)) 個非隱藏項" echo "----------------------------------------" # 可選:顯示詳細信息 read -p "是否顯示詳細信息?(y/n): " show_details case $show_details in [Yy]|[Yy][Ee][Ss]) echo "" echo "普通文件列表:" find "$directory" -maxdepth 1 -type f -not -name ".*" -printf "%f\n" | sort echo "" echo "目錄文件列表:" find "$directory" -maxdepth 1 -type d -not -name ".*" -printf "%f\n" | grep -v "^\.$" | sort ;; *) echo "統(tǒng)計完成。" ;; esac

微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號