Linux中如何执行两个main函数

Linux中如何执行两个main函数,第1张

1.运行:本文使用一个简单的C程序(simple.c)。代码如下: int main() { return(0)} 2. 编译:~#gcc -o simple simple.c 3. 查看可执行文件的基本信息~#objdump -f simple simple: file format elf32i386 architecture: i386, flags 0x00000112: EXEC_P, HAS_SYMS, D_PAGED start address 0x080482d0借助objdump这个工具,可以获得可执行文件的一些关键信息。

简单的实现,没有添加同步机制,回头再添加上去,而且,我是在不同终端里面写的,你可以把两段代码,一个放到父进程,一个放到子进程...就可以了你说的这些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关机并重启。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/7307378.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-04
下一篇 2023-04-04

发表评论

登录后才能评论

评论列表(0条)

保存