有时确实需要。从网上搜索了一段,测试结果正常。

#include <stdio.h>
#include <pwd.h>
#include <unistd.h>

int main(const int argc, const char** argv)
{
    struct passwd *pwd = getpwuid(getuid());
    printf("login account:%s\n", pwd->pw_name);

    //应该释放内存: free(pwd); pwd = NULL;
    return 0;
}