views:

13

answers:

0

Hi, all

I've tried to insert a piece of code in a prototype file system written in FUSE that can get ppid from the calling process id (fuse_get_context()->pid). It works well for normal read/write operations. However, if one program is going to execute a file (only on Mac OSX), this fs quits after hanging for a long time. The code is follows:

int foofs_open(const char *path, struct fuse_file_info *fi) { 
    pid_t pid = fuse_get_context()->pid;
    pid_t ppid = 0;
    struct kinfo_proc info;
    size_t length = sizeof(struct kinfo_proc);
    int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid };
    if (sysctl(mib, 4, &info, &length, NULL, 0) < 0)
        ppid = -1;
    if (length == 0)
        ppid = -1;
    ppid = info.kp_eproc.e_ppid;

    //... doing open operation works
}