linux下怎么在等待线程结束中设置超时

linux下怎么在等待线程结束中设置超时,第1张

有系统调用:pthread_timedjoin_np

The pthread_timedjoin_np() function performs a join-with-timeout. If thread has not yet terminated, then the call blocks until a maximum time, specified in

abstime. If the timeout expires before thread terminates, the call returns an error. The abstime argument is a structure of the following form, specifying

an absolute time measured since the Epoch (see time(2)):

struct timespec {

time_t tv_sec/* seconds */

long tv_nsec /* nanoseconds */

}

判断进程是否存在。示例:

timer=20 #20s定时器

flag=1 #标识进程是否存在

while [ $timer -gt 0 ]

do

    sleep 2

    ps -aux | grep 进程名 | grep -v grep >/dev/null #查询进程

    [ $? -ne 0 ] && flag=0 && break #进程不存在了就退出循环

    let timer-=1

done

[ $flag -eq 1 ] && kill -9 $(ps -aux | awk '/ bash$/{print $1}')

网络出现异常。

根据查询相关公开信息显示,网络出现异常,导致linux系统消息耗时过长,linux系统出现卡顿,导致消息耗时过长

线程(英语:thread)是 *** 作系统能够进行运算调度的最小单位。


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存