Linux C程序异常退出怎么办

Linux C程序异常退出怎么办,第1张

在Linux上只要打开core dump文件开关吵胡碧,当程序crash时系统生成相应的core文件。下面是简单的一些步骤: 1.查看当前是否已经打开了此开关 通过命令:做握ulimit -c 如果输出为 0 ,则代表没有打开。如果为unlimited则升举已经打开了,就没必要在做打开。 2.

我用的linux as4 的 *** 作系统,重装了oracle数据库后,以前的老数据文件和里面的文件都不能删除,并且读写和执行的权限都赋权给了oracle和root这两个,删除时提示为只读系统文件,请高手指点如何修改文件,能给出相应的命令最好!

msgrcv.c 内容如凳歼下:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <sys/types.h>

#include <fcntl.h>

#include <sys/mman.h>

#include <errno.h>

#include <sys/ipc.h>

#include <sys/msg.h>

#define N 10

typedef struct student

{

int sno

char sname[15]

}STU

typedef struct msgbuf

{

long mtype

STU stu[N]

}MSGBUF

main(int argc, char* argv[])

{

int i = 0

MSGBUF mbf = {0}

mbf.mtype = 1

int MSQID

errno = 0

char *name = "./msgaaa"

key_t key = ftok(name,0)

MSQID = msgget(key, IPC_CREAT)

while(i <N)

{

mbf.stu[i].sno = i

strcpy(mbf.stu[i].sname, "hello")

if (i == 1)

{

memset(mbf.stu[i].sname, 0, strlen(mbf.stu

[i].sname))

strcpy(mbf.stu[i].sname, "aaa"迟旁)

}

if (i == N-1)

{

memset(mbf.stu[i].sname, 0, strlen(mbf.stu

[i].sname))

strcpy(mbf.stu[i].sname, "end")

}

printf("------- %s ------", mbf.stu[i].sname)

msgsnd(MSQID, mbf.stu[i], sizeof(mbf.stu[i]), 0)

if (-1 == errno)

{

perror("msgsnd")

exit(-1)

}

printf(" %d -- %s\n", mbf.stu[i].sno, mbf.stu[i].sname)

i++

sleep(1)

}//while

msgctl(MSQID, IPC_RMID, NULL)

}

msgsnd内容如下:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <码粗橡sys/types.h>

#include <fcntl.h>

#include <sys/mman.h>

#include <errno.h>

#include <sys/ipc.h>

#include <sys/msg.h>

#define N 10

typedef struct student

{

int sno

char sname[15]

}STU

typedef struct msgbuf

{

long mtype

STU stu[N]

}MSGBUF

main(int argc, char* argv[])

{

int i = 0

MSGBUF mbf = {0}

mbf.mtype = 1

int MSQID

errno = 0

char *name = "./msgaaa"

key_t key = ftok(name,0)

MSQID = msgget(key, IPC_CREAT)

while(i <N)

{

mbf.stu[i].sno = i

strcpy(mbf.stu[i].sname, "hello")

if (i == 1)

{

memset(mbf.stu[i].sname, 0, strlen(mbf.stu[i].sname))

strcpy(mbf.stu[i].sname, "aaa")

}

if (i == N-1)

{

memset(mbf.stu[i].sname, 0, strlen(mbf.stu[i].sname))

strcpy(mbf.stu[i].sname, "end")

}

// printf("------- %s ------", mbf.stu[i].sname)

msgsnd(MSQID, mbf.stu[i], sizeof(mbf.stu[i]), 0)

if (-1 == errno)

{

perror("msgsnd")

exit(-1)

}

printf(" %d -- %s\n", mbf.stu[i].sno, mbf.stu[i].sname)

i++

sleep(1)

}//while

msgctl(MSQID, IPC_RMID, NULL)

}

msgsnd 显示结果:

0 -- hello

1 -- aaa

2 -- hello

3 -- hello

4 -- hello

5 -- hello

6 -- hello

7 -- hello

8 -- hello

9 -- end


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存