Linux学习
Nemoxy
咸鱼一条,希望自己写的东西能给大家带来帮助~
展开
-
linux : my_ls实现
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <dirent.h>#include <string.h>#include <sys/types.h>#include <sys/ioctl.h>#include <sys/stat.h>#include <time.h>//最大文件名长度512,文件数量原创 2020-10-31 15:27:13 · 219 阅读 · 0 评论 -
linux: shell实现线性筛
要点shell中数组的表示及初始化test表达式,运算表达式,if表达式,for表达式,赋值表达式输入参数的表示,如$@, $#, $0, $1…#!/bin/bash#输入一定范围内素数#declare -a primefunction usage(){ printf "Usage : %s start_num end_num\n" $0}#初始化数组function init(){ s=$1 e=$2 for (( i=$s; i<=$原创 2020-10-29 22:55:31 · 224 阅读 · 0 评论 -
linux: exec实战
打开一个.c文件,并编译,如果编译成功,则继续执行这个.c文件。#include<stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <wait.h>int main(int argc, char *argv[]){ char filename[512]; if (argc < 2){ fprintf原创 2020-10-29 20:54:42 · 150 阅读 · 0 评论 -
linux: my_cat实现
功能:-b 空行不标行号-n 空行标行号现在版本不支持读入多个文件,可以类似 ./a.out -b test -n test,因为optind每次while后都不移动,所以不知道如何实现类似./a.out -b test1 test2,多个文件读入。Code:知识点:getopd, fopen, fgets函数特性/************************************************************************* > File Nam原创 2020-10-29 20:54:26 · 113 阅读 · 0 评论 -
linux: 初识pthread
注意点pthread_create 与pthread_join成对出现注意传参格式,pthread_create(&线程id, NULL, (func *)类型函数地址, (void *)变量或结构体地址);,函数定义则是void *函数名(void *arg),函数内部要先把void指针arg强转为指定类型,如结构体可以新声明一个变量。也可以写成printf("My name is %s, age is %d\n", ((struct Mystruct *)arg)->name, ((原创 2020-10-29 20:53:00 · 123 阅读 · 0 评论 -
linux: 使用多进程,编写简单命令my_exec
/************************************************************************* > File Name: 2.100_child.c > Author: suyelu > Mail: [email protected] > Created Time: Sat 17 Oct 2020 03:05:43 PM CST *************************************************原创 2020-10-29 20:52:34 · 175 阅读 · 0 评论 -
linux:输出文件/目录中最长字符串
最简单版本#find_max.sh#!/bin/bash#if [[$# lt 1]];then# echo "Usage : %s file[...]\n" $0#fimax_len=0max_str=''for i in `cat $1 | tr -s -c "a-zA-Z" " "`; do len=${#i} if [[ ${len} -gt ${max_len} ]];then max_len=${len} max_str=${i}原创 2020-10-20 16:42:19 · 443 阅读 · 0 评论