|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
各位大神,求助一个问题,为什么我创建了一个线程,但ps时会出现3个同名的进程呢?
[root@~]#ps
PID USER VSZ STAT COMMAND
1 root 1360 S init
2 root 0 SW< [kthreadd]
3 root 0 SW< [ksoftirqd/0]
4 root 0 SW< [events/0]
5 root 0 SW< [khelper]
8 root 0 SW< [async/mgr]
93 root 0 SW< [kblockd/0]
104 root 0 SW< [khubd]
125 root 0 SW [pdflush]
126 root 0 SW [pdflush]
127 root 0 SW< [kswapd0]
188 root 0 SW< [mtdblockd]
247 root 0 DW< [yaffs_c1eec000]
250 root 0 DW< [yaffs_c1eea000]
269 root 1352 S /sbin/syslogd -n -O /var/log/messages -s 32 -b 1 -m 20
272 root 1360 S /sbin/klogd -n
274 root 2896 S /sbin/inetd
275 root 1356 S {console.sh} /bin/sh /etc/init.d/console.sh
280 root 1356 S getty -L 115200 /dev/ttyS0 vt100
282 root 2564 S /MeterRoot/LEDRoot/LEDwd
284 root 2444 S /MeterRoot/LEDRoot/LEDsm
285 root 5564 S /MeterRoot/LEDRoot/LEDcd
293 root 2036 S /MeterRoot/LEDRoot/LEDapn
294 root 3176 S /MeterRoot/LEDRoot/LEDtask
303 root 2560 S /MeterRoot/LEDRoot/LEDdel
304 root 5176 S /MeterRoot/LEDRoot/LEDsc
308 root 3084 S /MeterRoot/LEDRoot/LEDtt
13363 root 1360 S /sbin/telnetd
13364 root 1368 S -sh
13977 root 0 SW< [scsi_eh_0]
13978 root 0 SW< [usb-storage]
14045 root 1360 S /sbin/telnetd
14046 root 1368 S -sh
14161 root 7152 S /MeterRoot/LEDRoot/LEDplc
14164 root 2288 S /MeterRoot/SYSUtils/pppd call gprs
14167 root 7152 S /MeterRoot/LEDRoot/LEDplc
14168 root 7152 S /MeterRoot/LEDRoot/LEDplc
14178 root 1356 R ps
void *heartBeatPthread(void *arg)
{javascript:;
int ret;
int j,alarmflag=0;
time_t nowTime;
struct tm *nowTimeStruct;
time(&nowTime);
nowTimeStruct = localtime(&nowTime);
int sumTime = 0; //累计进入广播的时间
int sumTime_key = 0; //累计进入组网的时间
char *sqlorder;
for(;;)
{
sleep(1);
sumTime++;
sumTime_key++;
pthread_mutex_lock(&mutex);
nowTime = time(NULL);//UTC
nowTimeStruct = localtime(&nowTime);//当前时间结构体
if(broadFlag > 0)
{
broadFlag ++;
}
/************************广播对时*******************************/
if((1800+offSet) == sumTime || broadFlag > (offSet/3+5))
{
sumTime = 0;
broadFlag = 0;
memset(userdata, 0, 256);
userdata[0] = 0x0a;
userdata[1] = nowTimeStruct->tm_sec + 0x33; //秒
userdata[2] = nowTimeStruct->tm_min + 0x33; //分
userdata[3] = nowTimeStruct->tm_hour + 0x33; //时
userdata[4] = nowTimeStruct->tm_mday + 0x33; //日
userdata[5] = nowTimeStruct->tm_mon + 0x01 + 0x33; //月
userdata[6] = nowTimeStruct->tm_year -0x64 + 0x33; //年
memcpy(userdata+7, &send_count, 4);
ret = msgBroadToSlaveNode(broadcast_node, 0x08, broadcastAfn, F3);
sleep(3);
for(j=0;j<10;j++)
{
if(LEDPLC_OK == getHostNodeAddr()) /*获取主节点地址*/
{
if(1 == alarmflag)
{
sqlorder = "insert into ALARM([Alarm_Code],[Start_Stop],[Fault _Type],[Upload_Status]) values(9,0,5,0);";
sqliteInsert(sqlorder);
sendSocketWarnMsg(9, 0x00);
}
alarmflag = 0;
printf("getHostNodeAddr is sucess!!!!!!!!!!!!!!!!!!\n");
break;
}
if(9 == j && 0 == alarmflag)
{
alarmflag = 1;
sqlorder = "insert into ALARM([Alarm_Code],[Start_Stop],[Fault_Typ e],[Upload_Status]) values(9,1,5,0);";
sqliteInsert(sqlorder);
sendSocketWarnMsg(9, 0x01);
}
}
}
/************************广播对时*******************************/
/************************PLC组网*******************************/
if(1800 == sumTime_key)
{
sumTime_key = 0;
plcKeyUpdate();
}
/************************PLC组网*******************************/
/************************半夜更新策略*******************************/
if(((strategyTime+offSet)/60) != nowTimeStruct->tm_hour && 1 == tomorrowFlag)
{
tomorrowFlag = 0;
}
//添加strategyTime 变量,进程开始读数据库,读失败或者零值默认为21点
if((((strategyTime+offSet)/60)) == nowTimeStruct->tm_hour && ((strategyTime+of fSet)%60) <= nowTimeStruct->tm_min && 0 == tomorrowFlag)
{
tomorrowFlag = 1;
getPoolNum();
singleStrategyUpdate();
}
/*************************半夜更新策略*******************************/
pthread_mutex_unlock(&mutex);
}
}
创建线程:
pthread_attr_init(&attr); /*初始化线程属性*/
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED); /*设置为分离线程*/
if(0 != pthread_create(&heartbeattid, &attr, heartBeatPthread, NULL))
{
printf("Create getWarnPthread is failed!\n");
return LEDPLC_ERROR;
}
pthread_attr_destroy(&attr);
就是创建这个线程,ps后就会出现3个以上的进程。我想知道这个和内核,以及busybox有没有关系。因为我之前是用的2.6.34是没问题的,而现在用的是2.6.31的,busybox的版本是1.21.1的。
希望大神们指点迷津。
谢谢! |
-
-
|