fifo

Weird behaviour of fifos on linux

旧巷老猫 提交于 2019-12-10 11:49:16
问题 I'm studying linux fifos and I made two small C programs which communicate through fifo. The first one acts like a server, it receive a pattern and executes a command using that pattern. The second one acts like a client, it sends the pattern and receive the result. I want the server to be capable of serving multiple requests, not necessarily simultaneously, but the weird thing is that after the first client is served it just stops although I put there an infinite loop. server.c #include <sys

linux系统编程:命名管道FIFO和mkfifo函数

本秂侑毒 提交于 2019-12-09 20:50:10
进程间通信必须通过内核提供的通道,而且必须有一种办法在进程中标识内核提供的某个通道,前面讲过的 匿名管道 是用打开的文件描述符来标识的。如果要互相通信的几个进程没有从公共祖先那里继承文件描述符,它们怎么通信呢?内核提供一条通道不成问题,问题是如何标识这条通道才能使各进程都可以访问它?文件系统中的路径名是全局的,各进程都可以访问,因此可以用文件系统中的 路径名 来标识一个IPC通道。 FIFO和UNIX Domain Socket这两种IPC机制都是利用文件系统中的 特殊文件 来标识的。 FIFO文件在磁盘上没有数据块,仅用来标识内核中的一条通道 ,如 prw-rw-r-- 1 simba simba 0 May 21 10:13 p2,文件类型标识为p表示FIFO,文件大小为0。 各进程可以打开这个文件进行read/write,实际上是在读写内核通道(根本原因在于这个file结构体所指向的read、write函数和常规文件不一样),这样就实现了进程间通信。UNIX Domain Socket和FIFO的原理类似,也需要一个特殊的socket文件来标识内核中的通道,例如/run目录下有很多系统服务的socket文件: srw-rw-rw- 1 root root 0 May 21 09:59 acpid.socket ....................

第15章 进程间通行 15.5 FIFO

狂风中的少年 提交于 2019-12-09 20:35:20
(1)什么是命名管道,未命名管道? 未命名管道:只能在两个相关的进程之间使用,而且这两个相关的进程还要有一个共同的创建了它们的主先进程。 命名管道:FIFO,不相关的进程也能交换数据。 (2)FIFO是一种文件类型。 创建FIFO类似于创建文件,且FIFO的路径名存在与文件系统中。 (3) 函数mkfifo,mkfifoat创建FIFO,用open打开它(O_NONBLOCK非阻塞标志的影响)。 应用程序可以用mknod和mknodat函数创建FIFO。 (4)FIFO有两种用途。 1)复制一系列shell命令中的输出流。比如需要对一个经过过滤的输入流进行两次(单独)处理。 (通过tee程序实现:此程序将其标准输入同时复制到其标准输出以及其命令行中命名的文件中) 2)使用FIFO进行客户进程-服务器进程通行。 来源: oschina 链接: https://my.oschina.net/u/2463708/blog/518316

SQL First In First Out Loyalty Point

天涯浪子 提交于 2019-12-09 18:21:42
问题 fellow developers and analysts. I have some experience in SQL and have resorted to similar posts. However, this is slightly more niche. Thank you in advance for helping. I have the below dataset (edited. Apology) Setup CREATE TABLE CustomerPoints ( CustomerID INT, [Date] Date, Points INT ) INSERT INTO CustomerPoints VALUES (1, '20150101', 500), (1, '20150201', -400), (1, '20151101', 300), (1, '20151201', -400) and need to turn it into (edited. The figures in previous table were incorrect) Any

Attach to MySQL client entirely via FIFOs

。_饼干妹妹 提交于 2019-12-09 12:51:50
问题 On a Bash script I want to keep MySQL sessions open across several sequential accesses; the common way to access MySQL is by opening an individual session for each SQL command, or set of commands, such as mysql -u user -e "show tables;" The limitation of this method is the loss of atomicity and lock statuses for those transactions which need to be twofold: for example, it's not possible to preserve the lock status on a table T for the whole length of the following twofold operation: ###

UART在4412上的裸机开发

百般思念 提交于 2019-12-09 12:46:32
UART(通用异步传输收发器)简介 串行通信简介 我们的实际生活中,常见的通信方式有很多,例如:蓝牙,WIFI,网线,红外,HDMI VGA,USB,I2C,SP1,UART等,每种都有自己的特点以及常用的场合。今天,我们就来看看我们的串行通信。通用异步收发器简称UART,即“Universal Asynchronous Receiver Transmitter”, 它 串行通信是指计算机与I/O 设备之间数据传输的各位是按顺序依次一位接一位进行传送。通常数据在一根数据线上传输。具体情况如下:用来传输串行数据:发送数据时,CPU将并行数据写入UART,UART按照一定的格式在一根电线上串行发出;接收数据时,UART检测另一根电线上的信号,将串行收集放在缓冲区中,CPU即可读取UART获得这些数据。UART之间以全双工方式传输数据,最精简的连线方法只有三根电线:TxD用于发送数据,RxD用于接收数据,Gnd用于给双方提供参考电平,连线如图7.1所示:transmission recvfrom 我们通俗所使用的串口硬件格式为: 实质上,大部分我们只是使用了里面的3根线。 UART使用标准的TTL/CMOS逻辑电平(0~5V、0~3.3V、0~2.5V或0~1.8V四种)来表示数据,高电平表示1,低电平表示0。为了增强数据的抗干扰能力、提高传输长度,通常将TTL

ReentrantLock实现原理深入探究

杀马特。学长 韩版系。学妹 提交于 2019-12-09 10:58:53
前言 这篇文章被归到Java基础分类中,其实真的一点都不基础。网上写ReentrantLock的使用、ReentrantLock和synchronized的区别的文章很多,研究ReentrantLock并且能讲清楚ReentrantLock的原理的文章很少,本文就来研究一下ReentrantLock的实现原理。研究ReentrantLock的实现原理需要比较好的Java基础以及阅读代码的能力,有些朋友看不懂没关系,可以以后看,相信你一定会有所收获。 最后说一句,ReentrantLock是基于AQS实现的,这在下面会讲到,AQS的基础又是CAS,如果不是很熟悉CAS的朋友,可以看一下这篇文章 Unsafe与CAS 。 AbstractQueuedSynchronizer ReentrantLock实现的前提就是AbstractQueuedSynchronizer,简称AQS,是java.util.concurrent的核心,CountDownLatch、FutureTask、Semaphore、ReentrantLock等都有一个内部类是这个抽象类的子类。先用两张表格介绍一下AQS。第一个讲的是Node,由于 AQS是基于FIFO队列的实现 ,因此必然存在一个个节点,Node就是一个节点,Node里面有: 属 性 定 义 Node SHARED = new Node()

How to guarantee FIFO execution order in a ThreadPoolExecutor

南笙酒味 提交于 2019-12-09 04:48:17
问题 I create a ThreadPoolExecutor with this line of code : private ExecutorService executor = new ThreadPoolExecutor(5, 10, 120, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(20, true)); Then, I run 25 tasks (T01 to T25) so the situation is : 5 tasks currently running (T01 to T05) 20 tasks waiting in the Queue (T06 to T25) When I put 1 more task (T26), as the queue is full, I expected that the older task (T06) is removed to be launched (because MaxPoolSize is not reached) and the new task

Java Pig Latin sentence translator using Queues

坚强是说给别人听的谎言 提交于 2019-12-08 14:24:24
I am very new to Java and am trying to create a program to translate a sentence into Pig Latin, moving the first letter of the word to the end and appending "y" at the end if the first letter was a vowel and "ay" at the end otherwise. I am required to use a queue for this. Currently my program is just terminating and I was wondering if anyone might be able to spot where I am going wrong or where to head next. Thanks! import MyQueue.QueueList; import java.util.Scanner; public class PigLatin { public static void main (String[] args) { Scanner scan = new Scanner (System.in); QueueList word = new

java对象池ObjectPool

核能气质少年 提交于 2019-12-07 21:36:33
commons-pool提供了一套很好用的对象池组件。使用也很简单,不过对一些简单的对象使用对象池就没必要了。 ObjectPool定义了一个简单的池化接口,有三个对应实现 GenericObjectPool:实现了可配置的后进先出或先进先出(LIFO/FIFO)行为,默认是作为一个后进先出队列,这意味当对象池中有可用的空闲对象时,borrowObject 将返回最近的对象实例,如果将lifo 属性设置为false,则按FIFO行为返回对象实例。 StackObjectPool :实现了后进先出(LIFO)行为。 SoftReferenceObjectPool: 实现了后进先出(LIFO)行为。另外,对象池还在SoftReference 中保存了每个对象引用,允许垃圾收集器针对内存需要回收对象。 KeyedObjectPool定义了一个以任意的key访问对象的接口(可以池化对种对象),有两种对应实现。 GenericKeyedObjectPool :实现了先进先出(FIFO)行为。 StackKeyedObjectPool : 实现了后进先出(LIFO)行为。 PoolableObjectFactory 定义了池化对象的生命周期方法,我们可以使用它分离被池化的不同对象和管理对象的创建,持久,销毁。