作者BIAO (超越自己)
看板Linux
标题Fw: [问题] Linux C多执行绪的疑问!?
时间Fri May 2 11:30:46 2014
※ [本文转录自 C_and_CPP 看板 #1JOU9vFQ ]
作者: BIAO (超越自己) 看板: C_and_CPP
标题: [问题] Linux C多执行绪的疑问!?
时间: Thu May 1 13:58:15 2014
开发平台(Platform): (Ex: VC++, GCC, Linux, ...)
Linux
-------------------------------
各位板友大家好,
目前小弟有个程式,内有A、B两个thread,共用某个副程式,
其中A thread固定时间会执行该副程式,
另个B thread则随机等候外部命令,接收外部命令後执行该副程式。
此程式在Linux内执行,
可有时候会自己中断执行,
请问这是因为没使用mutex,
发生冲突导致程式结束吗!?
另想请问板友...
有什麽因素导致程式执行时,会自动结束呢!?
还请板友不吝赐教,谢谢..XD
--
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.124.42.70
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1398923897.A.3DA.html
※ 编辑: BIAO (140.124.42.70), 05/01/2014 14:15:52
1F:推 acake:两个thread有需要用mutex同步吗? 05/01 20:10
2F:推 RouterHsieh:没有产生core dump吗? 05/01 22:04
3F:→ RouterHsieh:话说这问题跟本板没啥关系..转去LinuxDev比较恰当吧 05/01 22:05
4F:→ BIAO:谢谢两位板友的回覆,我转到Linux.. XD 05/02 11:30
※ 发信站: 批踢踢实业坊(ptt.cc)
※ 转录者: BIAO (140.124.42.70), 05/02/2014 11:30:46
5F:→ bitlife:你自少要知道结束原因,程式自己正常exit,一般signal 或 05/02 11:53
6F:→ bitlife:SIGSEGV 05/02 11:53
7F:→ BIAO:我的程式是设定...无穷回圈 二个thread都是.. 所以才纳闷XD 05/02 13:00
8F:→ bitlife:所以我说要先找出原因,你可以先用交谈式shell把程式丢背景 05/02 13:32
9F:→ bitlife:shell不要登出,等程式结束,shell会显示程式怎麽结束的 05/02 13:33
10F:→ BIAO:谢谢b大.. 没用过shell!不过现在明白处理方式了,感谢您~~~ 05/02 13:50
11F:→ bitlife:你用linux但没用过shell?这...? 那你怎麽跑程式的? 05/02 14:50
回b大的话...
我都是用vim编辑C code,
用gcc编译後,直接用sudo ./执行程式..
偶尔加个&来背景执行.. XD
※ 编辑: BIAO (140.124.42.70), 05/02/2014 15:04:57
12F:→ bitlife:你sudo那行命令应该就是在交谈式shell下执行的 05/02 15:10
13F:→ bitlife:执行 echo $SHELL 就知道你目前是用什麽shell 05/02 15:11
14F:→ BIAO:(!!!) 原来是这个样子..谢谢b大 :D 05/02 15:16
15F:→ BIAO:目前已物色到一本不错的书..准备入手!! 05/02 15:20
16F:→ BIAO:我是用bash~~~ 05/02 16:16
目前已经完全懂b大的意思..
我的确是在interactive mode执行程式,
不过就算执行没加上&,程序自行结束时也没有产生程序如何结束..
我是使用Ubuntu Linux,目前在寻找产生Core dump的方法XD
C语言程序是无穷回圈,二个thread都是..
※ 编辑: BIAO (140.124.42.70), 05/02/2014 21:25:13
※ 编辑: BIAO (140.124.42.70), 05/02/2014 21:26:33
17F:→ kdjf:gcc -g (debug), 加上gdb试试看吧 05/02 21:51
18F:→ lantw44:$SHELL 是登入的时候设定的,如果自己开其他 shell 05/02 22:46
19F:→ lantw44:不会跟着变 05/02 22:46
20F:→ bitlife:楼上,我是看原po连shell是什麽都不知道,所以才叫他看目前 05/02 23:21
21F:→ bitlife:是什麽shell XD 05/02 23:21
22F:→ bitlife:不过你这补充说明对原po还是有用就是了 05/02 23:23
感谢大家的回覆,参照k大做法,
采用gcc -o -g -DDEBUG modbus+MySQL+Control26 modbus+MySQL+Control26.c
-I/usr/include/mysql -L/usr/lib/mysql -lmysqlclient -lpthread,
得到了许多资讯..
-------------------------------------
modbus+MySQL+Control26: In function `_fini':
crtstuff.c:(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crti.o:(.fini+0x0):
first defined here
modbus+MySQL+Control26: In function `__data_start':
crtstuff.c:(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crt1.o:(.data+0x0):
first defined here
modbus+MySQL+Control26: In function `__data_start':
crtstuff.c:(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/crtbegin.o:(.data+0x0): first defined
here
modbus+MySQL+Control26:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crt1.o:(.rodata.cst4+0x0):
first defined here
modbus+MySQL+Control26: In function `_start':
crtstuff.c:(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crt1.o:(.text+0x0):
first defined here
modbus+MySQL+Control26: In function `_init':
crtstuff.c:(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crti.o:(.init+0x0):
first defined here
/tmp/ccj4NCbh.o:(.bss+0x0): multiple definition of `data_lock'
modbus+MySQL+Control26:(.bss+0x10): first defined here
/tmp/ccj4NCbh.o: In function `sock_server_thread':
modbus+MySQL+Control26.c:(.text+0x0): multiple definition of
`sock_server_thread'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:38:
first defined here
/tmp/ccj4NCbh.o: In function `order_dec':
modbus+MySQL+Control26.c:(.text+0x3f4): multiple definition of `order_dec'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:154:
first defined here
/tmp/ccj4NCbh.o: In function `control':
modbus+MySQL+Control26.c:(.text+0x7f4): multiple definition of `control'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:248:
first defined here
/tmp/ccj4NCbh.o: In function `status':
modbus+MySQL+Control26.c:(.text+0x2098): multiple definition of `status'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:697:
first defined here
/tmp/ccj4NCbh.o: In function `info':
modbus+MySQL+Control26.c:(.text+0x1204): multiple definition of `info'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:469:
first defined here
/tmp/ccj4NCbh.o: In function `main':
modbus+MySQL+Control26.c:(.text+0x378): multiple definition of `main'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:132:
first defined here
/tmp/ccj4NCbh.o: In function `modbustcp':
modbus+MySQL+Control26.c:(.text+0x2c20): multiple definition of `modbustcp'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:898:
first defined here
/tmp/ccj4NCbh.o: In function `modbusrtu':
modbus+MySQL+Control26.c:(.text+0x2f1c): multiple definition of `modbusrtu'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:1004:
first defined here
/tmp/ccj4NCbh.o: In function `info_insert':
modbus+MySQL+Control26.c:(.text+0x1c88): multiple definition of `info_insert'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:636:
first defined here
/tmp/ccj4NCbh.o: In function `cost_power':
modbus+MySQL+Control26.c:(.text+0x1e1c): multiple definition of `cost_power'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:660:
first defined here
/tmp/ccj4NCbh.o: In function `status_insert':
modbus+MySQL+Control26.c:(.text+0x2844): multiple definition of
`status_insert'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:839:
first defined here
/tmp/ccj4NCbh.o: In function `crc16':
modbus+MySQL+Control26.c:(.text+0x321c): multiple definition of `crc16'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:1114:
first defined here
collect2: ld returned 1 exit status
ubuntu@localhost:~/C-practice/Test$
-------------------------------------
这些资讯是没加上-g不会出现的..XD
※ 编辑: BIAO (140.124.42.70), 05/03/2014 13:18:36