
简单的实现,没有添加同步机制,回头再添加上去,而且,我是在不同终端里面写的,你可以把两段代码,一个放到父
进程,一个放到子进程...就可以了你说的这些API,自己man 一次,看看说明就知道用法了.... 楼上说的对齐的问题,我没有太注意..不过,不管你要共享什么,一个sizeof看看大小,一个memcpy
拷贝,你就作为数据直接拷贝到共享内存区域就OK了...另外一边再拷贝回来,用一个结构体类型的指针指向你拷贝回来的数据,不就给这部分内存再规划成一个结构体了。。至于具体的, KEY 的含义,你需要了解linux的ipc机制。 #include #include #include #include #define BUF_SIZE 100 #define KEY 99 int main(void) { int shmidchar *shmptrshmid=shmget(99,BUF_SIZE,IPC_CREAT|0666)if(shmid==-1) { printf("Shared Memory Created error...\n")exit(0)} shmptr=shmat(shmid,NULL,0)if(shmptr==(void*)-1) { printf("shmat error,shmptr= %d \n",shmptr)exit(1)} while(1) { printf("type strings into Shared Memory:")fgets(shmptr,BUF_SIZE,stdin)} return 0} 下面这段就每隔10秒钟扫描共享内存区域的内容: #include #include #include #include #define BUF_SIZE 100 #define KEY 99 int main(void) { int shmidchar *shmptrshmid=shmget(99,BUF_SIZE,IPC_CREAT|0666)if(shmid==-1) { printf("Shared Memory Created error...\n")exit(0)} shmptr=shmat(shmid,NULL,0)if(shmptr==(void*)-1) { printf("shmat error,shmptr= %d \n",shmptr)exit(1)} while(1) { printf("Infomation in Shared Memory:")printf("%s \n",shmptr)sleep(10)} return 0}
1、打开shell连接抄工具,连接上服务器,pwd查看当前目录,一般进来默认在主目录下。
2、通过命令:cd /切换到主目录下,然后pwd查看当前目录,并用ls可以查看当前目录下的文件及目录。
3、假如要找一个nginx配置文件nginx.conf,那么可以通过find命令查找:find . -name 'nginx.conf'。
4、假如不知道文件的具体名字只是模糊记得几个关键的单词,那么就可以通过模糊匹配去搜索:find 目录 -name '*nginx*' 查找即可。
扩展资料:
shutdown.exe -a取消关机。
shutdown.exe -s 关机。
shutdown.exe -f强行关闭应用程序。
shutdown.exe -m \\计算机名 控制远程计算机。
shutdown.exe -i显示图形用户界面,但必须是Shutdown的第一个参数。
shutdown.exe -l注销当前用户。
shutdown -r关机并重启。
评论列表(0条)