linux共享内存使用实例
三个文件,一个头文件,一个读,一个写,用同一个key值申请共享内存。
//shm.h
#ifndef _SHM_COM_H
#define _SHM_COM_H 1
#define TEXT_SZ 2048
struct shared_use_at
{
int written_by_you;
char some_text[TEXT_SZ];
};
struct kts
{
int power;
int mode;
int temp;
int windspeed;
int write_flag;
};
#endif
//shm_write.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include "shm.h"
int main()
{
int running = 1;
void *shared_memory = (void *)0;
struct shared_use_at *shared_stuff;
char buffer[BUFSIZ];
int shmid;
shmid = shmget((key_t)1234, sizeof(struct shared_use_at), 0666 | IPC_CREAT);
if(shmid == -1)
{
fprintf(stderr, "shmget failed\n");
exit(EXIT_FAILURE);
}
shared_memory = shmat(shmid, (void *)0, 0);
if(shared_memory == (void *)-1)
{
fprintf(stderr, "shmat failed\n");
exit(EXIT_FAILURE);
}
printf("Memory attached at %X\n", (int)shared_memory);
shared_stuff = (struct shared_use_at *)shared_memory;
while(running)
{
while(shared_stuff->written_by_you == 1)
{
sleep(1);
printf("waiting for client...\n");
}
printf("Enter some text: ");
&n
相关文档:
总览
用iptables -ADC 来指定链的规
则
,-A添加 -D删除 -C 修改
iptables - [RI] chain rule num rule-specification[option]
用iptables - RI 通过规则的顺序指定
iptables -D chain rule num[option]
删除指定规则
iptables -[LFZ] [chain][option]
用iptables -LFZ 链名 [选项]
iptables -[NX] chain
用 -NX ......
MAC地址为网卡的物理地址,在Windows系统下非常容易修改,在linux模式下则有些复杂, 我们看看VMware虚拟机中修改Linux MAC地址的方法
方法一:
这个方法最直接简单有效,修改Linux系统里相关rc.local文件MAC值即可。
方法二:
修改虚拟机的*.vmx文件,这种方法最值得推荐,因为这样就类似于重新“烧录”了VMw ......
平时一般用ps来查看进程信息,赶紧就够了。今天需要知道详细的路径,一时还想不起来。记得有个参数,可以改变ps的输出里面cmd的显示宽度,可惜记不清了。回头再找找。
http://www.svn8.com/linux/glpz/20100221/22543.html
这个上面介绍的方法是根据pid在/proc/pid_number 下面查看具体信息。就是有点小麻烦。 ......
vi与vim一样都是编辑器,不同的是vim更高级一些,可以理解是vi的高级版本。vi就像Windows中的计事本,而vim则可以算的上是
office中的word。vi主要用来编辑一些文件,vim是程序员的好工具。好的。。。。下面在介绍一下vi的使用。。。。。。
1.
使用vi进入一般模式
[root@linux ~]# vi test.tx ......
# uname -a
Linux euis1 2.6.9-55.ELsmp #1 SMP Fri Apr 20 17:03:35 EDT 2007 i686 i686 i386 GNU/Linux
(查看当前操作系统内核信息)
# cat /etc/issue | grep Linux
Red Hat Enterprise Linux AS release 4 (Nahant Update 5)
(查看当前操作系统发行版信息)
# cat /proc/cpuinfo | grep name | cut -f2 -d: ......