![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Linux操作系统
小小匠IT
这个作者很懒,什么都没留下…
展开
-
Linux库相关概念及编程(面试)
一:库https://www.cnblogs.com/sunsky303/p/7731911.htmlhttps://blog.csdn.net/wk_bjut_edu_cn/article/details/81735956(1):静态库静态函数库,是在程序执行前(编译)就加入到目标程序中去了 ;优点: 运行快发布程序无需提供静态库,因为已经在app中,移植方便缺点:大(2):动态库动态函数库,是在程序执行时动态(临时)由目标程序去调...原创 2020-12-20 15:08:24 · 67 阅读 · 0 评论 -
Linux库分文件编程(面试)
分文件编程案例:好处:分模块的编程思想 网络 a 超声波b 电机c a.功能责任划分 b.方便调试 c.主程序简洁main.c //主函数config.c //功能函数config.h //config.c 中函数的声明主函数中需要包含 "config.h" 头文件;运行时:gcc config.c main.c //两个文件一起编译<...原创 2020-12-20 13:45:37 · 73 阅读 · 0 评论 -
Linux线程条件控制
创建条件:int pthread_cond_init(pthread_cond_t *cv,const pthread_condattr_t *cattr);返回值:函数成功返回0;任何其他返回值都表示错误等待条件:int pthread_cond_wait(pthread_cond_t *cv,pthread_mutex_t *mutex);返回值:函数成功返回0;任何其他返回值都表示错误触发条件:int pthread_cond_signal(pthread_cond_t *cv)..原创 2020-10-12 16:17:37 · 96 阅读 · 0 评论 -
Linux互斥锁
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr); 创建锁 int pthread_mutex_destroy(pthread_mutex_t *mutex); 销毁锁 int pthread_mutex_lock(pthread_mutex_t *mutex); 加锁 int pthread_mutex_unlock(pthread_mutex_t *mutex); 解锁.原创 2020-10-12 15:56:55 · 105 阅读 · 0 评论 -
Linux信号
信号的处理:信号的处理有三种方法:忽略,捕捉,和默认动作。 SIGKILL和SIGSTOP两种信号不能被忽略和捕捉。捕捉信号:执行自定义动作typedef void (*sighandler_t)(int);sighandler_t signal(int signum, sighandler_t handler); 信号 函数忽略信号:SIG_IGNsignal(SIGINT...原创 2020-10-11 13:46:22 · 190 阅读 · 0 评论 -
消息队列
#include <sys/types.h>#include <sys/ipc.h>#include <sys/msg.h>int msgget(key_t key, int msgflg); // 创建打开消息队列int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg); /...原创 2020-10-10 10:59:58 · 114 阅读 · 1 评论 -
linux线程创建
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); //线程创建函数 void pthread_exit(void *retval); //线程退出函数 int pthread_join(pthread_t thread, void **retval);...原创 2020-10-10 10:59:03 · 90 阅读 · 0 评论 -
共享内存
int shmget(key_t key, size_t size, int shmflg); //size:共享内存至少分配1兆(1024)大小//创建或获取一个共享内存,成功返回共享内存ID,失败返回-1。void *shmat(int shmid, const void *shmaddr, int shmflg);//连接共享内存到当前进程的地址空间; //成功返回指向共享内存的指针,失败返回-1。int shmdt(const void *shmaddr);//断开与共享内存的连.原创 2020-10-04 16:31:10 · 236 阅读 · 0 评论 -
创建命名管道
fifo:命名管道,它是一种特殊文件类型。特点:fifo可以在无关进程之间交换数据,与无名管道不同。 fifo有路径名,以一种特殊的设备文件形式存在于文件系统中。命名管道间的数据通信:当open一个fifo时,是否设置非阻塞标志(O_NONBLOCK)的区别:若没指定O_NONBLOCK,只读open要阻塞到其他进程为写而打开此 fifo。 只写open同上,也要阻塞到其他进程为读而打开此 fifo。#include <sys/types.h>#includ..原创 2020-10-02 10:22:58 · 278 阅读 · 0 评论 -
无名管道
无名管道:它是半双工的(数据只能在一个方向上流动)具有固定的读端和写端。 它只能用于父子进程或兄弟进程之间的通信。 它可以看成一种特殊的文件,它的读写可以使用read和write等函数;但它不是普通文件,不属于其他任何文件系统,只存在于内存中。 管道数据读走就没了。建立管道:int pipe(int fd[2]);返回值:成功返回0,失败返回-1。当一个管道建立时,它会创建两个文件描述符,f[0]为读而打开,f[1]为写而打开。fd[0]对应读: read(fd[0],__,__);.原创 2020-09-30 11:29:20 · 163 阅读 · 0 评论 -
exec族函数(初学者)
#include <unistd.h> extern char **environ; int execl(const char *path, const char *arg, ...); int execlp(const char *file, const char *arg, ...); int execle(const char *path, const char *arg,..., char * const envp[]); int execv(const char *path.原创 2020-09-29 11:12:39 · 151 阅读 · 0 评论 -
5:文件操作之实现cp指令
cp指令执行步骤:打开需要被拷贝的文件 读取文件内容 打开/创建要拷贝到的文件 将读取到的内容写入要拷贝的文件 关闭两个文件#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <stdio.h>#include <unistd.h>#include <string.h>#include <stdlib.h>.原创 2020-06-06 21:34:13 · 247 阅读 · 0 评论 -
4:文件操作原理简述
#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <stdio.h>int main(){ int fd; char *readbuf[128]; int n_read = read(0,readbuf,5); int n_write = write(1,readbuf.原创 2020-06-06 16:29:40 · 127 阅读 · 0 评论 -
3:文件的光标移动
#include <sys/types.h>#include <unistd.h>off_t lseek(int fd, off_t offset, int whence);lseek(int fd, off_t offset, int whence);注:lseek(文件,偏移值,光标位置);偏移值:为 0 不移动,大于 0 (正数)向后移动,小于 0 (负数)向前移动光标位置:SEEK_SET 文件头 S...原创 2020-06-06 15:19:15 · 161 阅读 · 0 评论 -
LINUX :(一)文件操作:1:文件的打开及创建
#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>int open(const char *pathname, int flags);int open(const char *pathname, int flags, mode_t mode);open函数的头文件可在Linux下用 man函数查找:man 2 open文件打开函数:open(要打开的文件名,打开方式);...原创 2020-06-03 21:14:55 · 472 阅读 · 0 评论 -
2:文件的写入和读取操作
ssize_t write(int fd, const void *buf, size_t count);ssize_t read(int fd, void *buf, size_t count);write(要写入的文件,写入的内容,内容的长度);read(要读取的文件,读取到指定的空间,读取的长度);write和read返回值:字节数write函数执行完以后光标会移到最后,此时read读取为空需要重新打开文件或将光标移动(lseek 函数)到文件头位置当写...原创 2020-06-04 15:43:18 · 223 阅读 · 0 评论