![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
学习笔记
程序喵阿呆
道济天下,智周万物
展开
-
二叉树实现
#include<stdio.h>#include<stdlib.h>#define NAMESIZE 32struct score_st{ int id; char name[NAMESIZE]; int math; int chinese;};struct node_st{ struct score_st data; struct node_st *l,*r;};void print_s(struct s...原创 2021-12-13 20:51:26 · 3582 阅读 · 0 评论 -
postgreSQL 学习
pg配置:SQL语法简介:原创 2021-12-04 16:54:40 · 67 阅读 · 0 评论 -
有限状态机编程
头文件relay.h#ifndef _RELAY__H_#define _RELAY__H_#include <stdlib.h>#define JOBMAX 10000enum { STATE_RUNNING = 1, STATE_CANCELD, STATE_OVER};struct relay_stat_st{ int state; int fd1; int fd2; int64_t count12, count21;};// retrurn原创 2021-11-07 23:44:17 · 230 阅读 · 0 评论 -
pthread学习--使用条件变量实现信号量
在实际开发过程,可能会控制某个模块所使用的资源,同一时刻只允许某个功能使用一定数量的资源。同样是筛质数,同一时刻只允许同时四个线程进行计算,所以需要使用一个信号量进行总资源的控制,代码如下://mysem.h#ifndef _MYSEM_H__#define _MYSEM_H__#include <pthread.h>//extern struct mysem;struct mysem { int val; pthread_mutex_t mutex;原创 2021-11-05 15:19:49 · 277 阅读 · 0 评论 -
线程学习--pthread--锁链及条件变量
pthread_cond_wait函数的使用,一般跟lock一起用pthread_mutex_lock(&mutex);pthread_cond_wait(&cond,&mutex);等待条件变量满足; 把获得的锁释放掉;(注意:1,2两步是一个原子操作) 当然如果条件满足了,那么就不需要释放锁。所以释放锁这一步和等待条件满足一定是一起执行(指原子操作)。--很重要。 pthread_cond_wait()被唤醒时,它解除阻塞,并且尝试获取锁(不一定拿到锁)。因此,一原创 2021-11-05 14:43:02 · 361 阅读 · 0 评论 -
线程学习--pthread-筛质数
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/types.h>#include <sys/wait.h>#include <pthread.h>#define LEFT 40000000#define RIGHT 40000200void *primer(void *arg){ int i = (int)arg.原创 2021-10-27 20:57:44 · 198 阅读 · 0 评论 -
mydeamon--守护进程实例
#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>static int deamonize(void){ pid_t pid = fork(); if(pid < 0) { perror("fork()"); exi.原创 2021-10-26 22:33:23 · 119 阅读 · 0 评论 -
mysudo--Linux用户权限管理实现
一直对Linux中的u+s权限不是很理解,一起来看看setuid的使用任何用户执行时,都以setuid程序文件所属的用户的身份运行。一般使用场景是,对归属root的程序进行setuid,以便普通用户有root用户的权限。上代码:#include <stdio.h>#include <stdlib.h>#include <wait.h>#include <unistd.h>#include <sys/types.h>in原创 2021-10-26 17:24:59 · 159 阅读 · 0 评论 -
execvp使用--实现自己的shell
#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/wait.h>#include <unistd.h>#include <string.h>#include <glob.h>static int parse(char *linebuf, glob_t *glob_res){ char *tok = "a.原创 2021-10-21 22:04:12 · 537 阅读 · 0 评论