Linux SHELL 获取进程ID

Linux SHELL 获取进程ID,第1张

slp后无论加不加&,pid中获取到的实际进程ID和main进程ID始终是一样的,因为slp函数是在当前脚本进程中运行。除非你调用外部脚本。

你可以在 slp &这句后加一句 ps >/tmp/log

然后看看slp后加&和不加&的情况下/tmp/log中显示的进程列表有何不同,就应该明白了。区别仅在于 $! 有值和没有值。

Linux下获取当前线程ID号函数:

pthread_t pthread_self()

返回:当前线程的ID号

pthread_t 数据类型的定义如下:

typedef unsigned long int pthread_t

sizeof(pthread_t) = 4,4个字节的整数。

Windows下获取当前线程ID号的函数:

DWORD GetCurrentThreadId()

返回值:当前线程的ID号

DWORD数据类型定义:

typedef unsigned long DWORD

在Windows下pthread-win库的pthread_t定义如下:

typedef struct {

void * p /*Pointer to actual object */

unsigned int x/*Extra information - reuse count etc */

} ptw32_handle_t

typedef ptw32_handle_t pthread_t

与Linux的thread_t不一样,它是一个结构,不是一个整数值

在Windows和Linux下可用的获取线程ID号的内联函数如下:

#ifdef WIN32

#include <windows.h>

#else

#include <pthread.h>

#endif

inline unsigned int PthreadSelf()

{

#ifdef WIN32

return::GetCurrentThreadId()

#else

returnthread_self()

#endif

}

如果你是copy或者克隆的虚拟机,打开时有提示让你选择是moved的还是copyed的,选择copy就会重设硬盘id,mac值可以system-config-network中把网卡mac重新生成一下。


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

原文地址:https://54852.com/yw/8621614.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存