![](https://img-blog.csdnimg.cn/20190918140129601.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
Linux环境编程
Linux环境编程
gdut17
这个作者很懒,什么都没留下…
展开
-
centos7配置samba连接win10
win操作:win删除所有samb用户信息net use * /del /ywin下添加网络凭据win+Rcontrol userpasswords2添加samba服务器地址 \\192.168.xx.xx添加samba用户,密码,必须是系统已经存在的用户Linux操作:1.安装sambayum install samba[root@localhost share]# cd /etc/samba/[root@localhost samba]# lslmhosts smb.c原创 2021-06-12 11:44:02 · 263 阅读 · 0 评论 -
WebSocket:Failed to execute ‘send‘ on ‘WebSocket‘: Still in CONNECTING state.
ws = new WebSocket(‘ws://192.168.150.53:8080/websocket’);ws.send(“111”);因为ws连接还没有建立成功,不能在new完后直接跟着send。js代码:<script> var interval = 1000; var send = function (ws,message, callback){ waitForConnection(ws,function(){原创 2021-01-26 18:18:17 · 1963 阅读 · 1 评论 -
使用openssl m3u8解密 EXT-X-KEY:METHOD=AES-128,URI=xxx
F12步骤自动化脚本#这个预先生成strkey=30613464393634393866656565386165#一共有120个小文件for j in $(seq 0 119)do #echo $j iv=$(printf '%032x' $j) #echo $iv input="./ts/"$j".mp4" output="./output/"$j"_out.mp4" #echo $input #echo $output openssl aes-128-原创 2020-12-27 10:01:41 · 21125 阅读 · 5 评论 -
git命令
查看所有分支git branch -rgit branch -a切换分支git checkout v1clone某个分支git clone -b dev5 https://git.coding.net/aiyongbao/tradepc.git原创 2020-12-19 19:30:53 · 97 阅读 · 1 评论 -
Module containing this breakpoint has not yet loaded or the breakpoint address not be obtained
gcc/g++ 加上-g选项原创 2020-12-16 00:13:53 · 4887 阅读 · 2 评论 -
VScode远程开发Linux C/C++程序
首先安装ssh,可以连接Linux虚拟机在vscode商店点击安装C/C++相关的在左侧栏点击齿轮的按钮,表示调试修改文件路径添加task.json修改为{ "version": "2.0.0", "tasks": [ { "type": "shell", "label": "g++ build active file", "command": "/usr/bin/g++", "args":原创 2020-12-15 21:33:43 · 536 阅读 · 0 评论 -
centos6停止yum维护解决办法
在此安装的是centos6最小系统修改CentOS-Base.repo# CentOS-Base.repo## The mirror system uses the connecting IP address of the client and the# update status of each mirror to pick mirrors that are updated to and# geographically close to the client. You should use原创 2020-12-14 17:33:30 · 1996 阅读 · 2 评论 -
Linux各种配置记录
查看版本[gdut17@localhost network-scripts]$ cat /etc/redhat-releaseCentOS release 6.5 (Final)配置静态ip[gdut17@localhost ~]$ cd /etc/sysconfig/network-scripts/[gdut17@localhost network-scripts]$ cat ifcfg-ifcfg-eth0 ifcfg-lo [gdut17@localhost network-s原创 2020-11-20 22:56:51 · 429 阅读 · 0 评论 -
gethostbyname & getaddrinfo
struct sockaddr { sa_family_t sin_family;//地址族 char sa_data[14]; //14字节,包含套接字中的目标地址和端口信息 }; struct sockaddr_in { sa_family_t sin_family; uint16_t sin_port; //2字节 struct in_addr sin_addr; //4字节 char原创 2020-10-23 13:55:27 · 374 阅读 · 0 评论 -
epoll LT
epoll实现主体摘自https://www.cnblogs.com/Anker/archive/2013/08/17/3263780.html添加了收发数据包的功能pack.h#ifndef _PACK_H_#define _PACK_H_//头文件内容//包头+包体 最大长度#define pack_max_length 10000#define _DATA_BUFSI...原创 2020-03-21 15:33:49 · 192 阅读 · 0 评论 -
pthread_spin自旋锁
如果互斥锁被占用,另一个线程进入时,互斥锁会引起线程切换。适合锁的内容比较多的自旋锁,如果锁被占用,来了的线程会一直等待直到获取这把锁相当于while(1);适合锁的内容比较少的当线程切换的代价远远比等待的代价大的时候,使用自旋锁#include <pthread.h> int pthread_spin_init(pthread_spinlock_t *loc...原创 2019-12-28 15:56:37 · 1794 阅读 · 0 评论 -
Linux下多线程传参问题
方法1pthread_create(&t_a[i],NULL,thread1,(void *)i);#include <pthread.h>#include <stdio.h>#include <stdlib.h>#include<unistd.h>void *thread1(void *arg){ printf...原创 2019-11-01 20:00:39 · 244 阅读 · 0 评论 -
linux编程实现三个线程ABC,并让它们顺次打印自己的ID,使用信号量
#include <pthread.h>#include <stdio.h>#include <semaphore.h>#include <errno.h>#include <stdlib.h>#include <unistd.h>static sem_t sem1,sem2,sem3; int global ...原创 2019-11-01 17:37:28 · 374 阅读 · 0 评论 -
5.线程与并发同步-哲学家用餐模型分析
多线程版:选用互斥锁mutex,如创建5个, pthread_mutex_t m[5];模型抽象: 5个哲学家 --> 5个线程; 5支筷子 --> 5把互斥锁 int left(左手), right(右手)5个哲学家使用相同的逻辑,可通用一个线程主函数,void *tfn(void *arg),使用参数来表示线程编号:int i = (int)arg;哲学家线程根据编号知...原创 2019-09-13 13:56:14 · 178 阅读 · 0 评论 -
进程间同步
进程间使用mutex来实现同步:#include <pthread.h>#include <sys/mman.h>#include <sys/wait.h>#include<stdio.h>#include<stdlib.h>#include <sys/types.h>#include <unistd.h&...原创 2019-09-13 12:53:09 · 224 阅读 · 0 评论 -
5.线程与并发同步- 编程实现,一个线程读用户输入, 另一个线程打印“hello world”。如果用户无输入,则每隔5秒向屏幕打印一个“hello wo
【作业】:结合生产者消费者信号量模型,揣摩sem_timedwait函数作用。编程实现,一个线程读用户输入, 另一个线程打印“hello world”。如果用户无输入,则每隔5秒向屏幕打印一个“hello world”;如果用户有输入,立刻打印“HELLO WORLD”到屏幕。#include<stdio.h>#include<unistd.h>#include<...原创 2019-09-13 01:42:05 · 598 阅读 · 0 评论 -
5.线程与并发同步-生产者消费者信号量模型
进化版的互斥锁(1 --> N)由于互斥锁的粒度比较大,如果我们希望在多个线程间对某一对象的部分数据进行共享,使用互斥锁是没有办法实现的,只能将整个数据对象锁住。这样虽然达到了多线程操作共享数据时保证数据正确性的目的,却无形中导致线程的并发性下降。线程从并行执行,变成了串行执行。与直接使用单进程无异。 信号量,是相对折中的一种处理方式,既能保证同步,数据不混乱,又能提高线程并发。【练习】...原创 2019-09-13 01:14:40 · 203 阅读 · 0 评论 -
5.线程与并发同步-使用条件变量实现两个线程之间的同步
线程1打印9以内不是3的倍数,线程2打印3的倍数#include<pthread.h>#include<stdio.h>#include<unistd.h>pthread_cond_t cond = PTHREAD_COND_INITIALIZER;pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;...原创 2019-09-13 00:35:06 · 172 阅读 · 3 评论 -
5.线程与并发同步-pthread_mutex_t加锁步骤测试
看如下程序:该程序是非常典型的,由于共享、竞争而没有加任何同步机制,导致产生于时间有关的错误,造成数据混乱:#include <stdio.h>#include <pthread.h>#include <unistd.h>void *tfn(void arg){srand(time(NULL));while (1) {printf("hello ...原创 2019-09-12 23:57:47 · 188 阅读 · 0 评论 -
5.线程与并发同步-条件变量pthread_cond_t 实现生产者消费者
使用标准库queue队列入队—模仿生产出队—模仿消费pthread_cond_wait函数阻塞等待一个条件变量int pthread_cond_wait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex);函数作用:1.阻塞等待条件变量cond(参1)满足 2.释放已掌握的互斥锁(解锁互斥量)相当于pthr...原创 2019-09-10 13:37:01 · 247 阅读 · 0 评论 -
5.线程与并发同步-linux学习笔记-读写锁
一把读写锁具备三种状态:1. 读模式下加锁状态 (读锁)2. 写模式下加锁状态 (写锁)3. 不加锁状态读写锁特性: 1.读写锁是“写模式加锁”时, 解锁前,所有对该锁加锁的线程都会被阻塞。2.读写锁是“读模式加锁”时, 如果线程以读模式对其加锁会成功;如果线程以写模式加锁会阻塞。3.读写锁是“读模式加锁”时, 既有试图以写模式加锁的线程,也有试图以读模式加锁的线程。那么读写锁会阻塞...原创 2019-09-10 10:18:11 · 119 阅读 · 0 评论 -
5.线程与并发同步-linux学习笔记-死锁
1.自己锁自己,重复加锁1.重复加锁#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <string.h>#include <pthread...原创 2019-09-09 22:41:37 · 141 阅读 · 0 评论 -
pthread_pool,POSIX的线程池实现
线程池,根据命令行参数,传递连接的端口号,线程个数,任务个数(即连接次数)可以测试server的并发#include<arpa/inet.h>#include<string.h>#include<sys/socket.h>#include<pthread.h>#include<stdio.h>#include<uni...原创 2020-01-01 13:57:50 · 288 阅读 · 0 评论 -
关于listen函数的backlog
unix网络编程中这样解释指未完成队列和已完成队列之和man listenman 手册上这样解释:The behavior of the backlog argument on TCP sockets changed with Linux 2.2. Now it specifies the queue length for completely established s...原创 2019-12-25 13:49:48 · 307 阅读 · 0 评论 -
UDP server/client实例
#include<stdio.h>#include<stdlib.h>#include<sys/socket.h>#include<arpa/inet.h>#include<unistd.h>#include<string.h>#define SIZE 300int main(int argc,char *a...原创 2019-10-16 20:43:27 · 713 阅读 · 0 评论 -
io多路复用___select
#include<stdio.h>#include<stdlib.h>#include<sys/socket.h>#include<arpa/inet.h>#include<unistd.h>#include<string.h>#define SIZE 30int main(int argc,char *arg...原创 2019-10-12 20:20:38 · 92 阅读 · 0 评论 -
makefile编译文件夹下全部程序
废话不多说 上代码CC=g++INC=/usr/local/include/google/protobufLIB=/usr/local/liblib=protobufSRCS=$(wildcard *.cc *.cpp)OBJS=$(patsubst %.cpp,%.o,$(patsubst %.cc,%.o,$(SRCS)))server:$(OBJS) $(CC) -g...原创 2020-04-12 10:05:50 · 221 阅读 · 0 评论 -
基于C的socket编程实现linux虚拟机和windows传输文件(图片)
linux服务端g++ linux_socket.cpp -o linuxsock/* linux端读取文件数据 */#include<stdio.h>#include<stdlib.h>#include<sys/socket.h>#include<arpa/inet.h>#include<unistd.h>...原创 2019-10-11 23:23:13 · 394 阅读 · 0 评论