网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

linux挂起线程命令 linux 挂起线程

关于Linux 线程pthread_join的用法

Linux系统pthread_join用于挂起当前线程(调用pthread_join的线程),直到thread指定的线程终止运行为止,当前线程才继续执行。

成都创新互联公司专注于企业全网整合营销推广、网站重做改版、兴城网站定制设计、自适应品牌网站建设、H5高端网站建设商城建设、集团公司官网建设、成都外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为兴城等各大城市提供网站开发制作服务。

案例代码:

/*******************************************

**    Name:pthread_join.c

**    用于Linux下多线程学习

**    案例解释线程的暂停和结束

**    Author:admin

**    Date:2015/8/11       

**    Copyright (c) 2015,All Rights Reserved!

**********************************************

#include pthread.h

#include unistd.h

#include stdio.h

void *thread(void *str)

{

int i;

//不调用pthread_join线程函数

for (i = 0; i  10; ++i)

{

sleep(2);

printf( "This in the thread : %d\n" , i );

}

return NULL;

}

int main()

{

pthread_t pth;

int i;

int ret = pthread_create(pth, NULL, thread, (void *)(i));

//调用pthread_join线程函数

pthread_join(pth, NULL);

for (i = 0; i  10; ++i)

{

sleep(1);

printf( "This in the main : %d\n" , i );

}

return 0;

}

通过Linux下shell命令执行上面的案例代码:

[root@localhost src]# gcc pthread_join.c -lpthread

[root@localhost src]# ./a.out

This in the main : 0

This in the thread : 0

This in the main : 1

This in the main : 2

This in the thread : 1

This in the main : 3

This in the main : 4

This in the thread : 2

This in the main : 5

This in the main : 6

This in the thread : 3

This in the main : 7

This in the main : 8

This in the thread : 4

This in the main : 9

子线程还没有执行完毕,main函数已经退出,那么子线程也就退出了,“pthread_join(pth, NULL);”函数起作用。

[root@localhost src]# gcc pthread_join.c -lpthread

[root@localhost src]# ./a.out

This in the thread : 0

This in the thread : 1

This in the thread : 2

This in the thread : 3

This in the thread : 4

This in the thread : 5

This in the thread : 6

This in the thread : 7

This in the thread : 8

This in the thread : 9

This in the main : 0

This in the main : 1

This in the main : 2

This in the main : 3

This in the main : 4

This in the main : 5

This in the main : 6

This in the main : 7

This in the main : 8

This in the main : 9

这说明pthread_join函数的调用者在等待子线程退出后才继续执行。

linux c语言怎样挂起线程/进程

线程

可以用pthread_kill函数

传递信号SIGSTOP挂起

传递SIGCONT 恢复

进程

调用系统的stop挂起

或者用kill -stop 挂起

类似的 用SIGCONT 恢复。

linux系统中挂起操作和强制结束操作(后台运行程序方法)

在linux系统中有这两个命令 ctrl+z 和ctrl+c ,这两个命令输入之后看起来结果差不多,实质是不同的。

他们都有中断命令的效果,但是作用是不一样的。

ctrl+c是强制终止程序的执行并结束进程。而ctrl+z则只是中断任务的执行,但该任务并没有被结束。

它只是在进程中维持挂起的状态,用户可以使用fg/bg命令来继续前台/后台执行该任务。fg命令会重启

前台被中断的任务,bg命令会把中断的任务放到后台执行。

你也可以使用bg这样的方法让一个前台执行的任务切换到后台去执行。

也可以使用fg这样的方法让一个后台执行的任务切换到前台去执行。

还有一个最常用的方法是

在一行命令的最后输入,可以让这行命令放到后台去运行。

使用jobs命令查看当前有多少后台程序在运行。


新闻标题:linux挂起线程命令 linux 挂起线程
本文URL:http://bjjierui.cn/article/doseigd.html

其他资讯