我对Linux API sem_unlink()有点困惑,主要是在什么时候或为什么调用它。我在Windows中使用信号量已经很多年了。在Windows中,一旦关闭了命名信号量的最后一个句柄,系统就会删除底层内核对象。但是在Linux中,开发人员需要通过调用sem_unlink()来删除内核对象。如果不这样做,内核对象将保留在/dev/shm文件夹中。
我遇到的问题是,如果进程A调用sem_unlink(),而进程B锁定了信号量,它会立即销毁信号量,现在当进程C出现时,进程B不再受信号量的“保护”。更重要的是,手册页充其量也是令人困惑的:
“信号量名称将立即删除。一旦打开信号量的所有其他进程将其
在我的应用程序中,我在父级和子级之间(在Linux和Windows上)为IPC使用共享内存。Linux的完整代码在上。
我在Linux上有下面的代码可以从共享内存中读取:
char buf[BUF_SIZE/4];
//pBuf is the shared memory location
sem_wait(semn);
//Wait for the parent process to write on the shared memory.
memcpy(buf, pBuf, sizeof(buf));
//Signal the parent
sem_post(sem0);
编写以下代码:
/
我的多线程代码中有很多自旋锁,大多数时候它们都在等待其他线程工作,因此占用了大量的cpu资源。在linux中,我通常使用pthread_cond_wait和pthread_cond_signal来暂停线程,并在收到信号时唤醒线程。boost库中有这样的东西吗?我匆匆看了一眼,什么也没找到。
Visual studio 2005
我计划在rootkit中使用我自己版本的getdents()。代码在这里:
asmlinkage int new_getdents(unsigned int fd, struct linux_dirent *dirp, unsigned int count)
{
int nread;
int bpos;
struct linux_dirent *d;
int (*orig_func)(unsigned int fd, struct linux_dirent *dirp, unsigned int count);
t_syscall_hook *open_