简体   繁体   English

如何删除另一个用户使用 C 创建的文件?

[英]how can I delete a file created by another user using C?

I have two C codes, the first code is called "Producer" and I run it in the user "A" and the code create a file.我有两个 C 代码,第一个代码称为“Producer”,我在用户“A”中运行它,代码创建一个文件。 The second code named "Consumer", is run in the user "B" and, this code read the file created by the "Producer" and need delete this file after end the reading.名为“Consumer”的第二个代码在用户“B”中运行,该代码读取“Producer”创建的文件,读取结束后需要删除该文件。 Both users "A" and "B" are in the group "ABshare".用户“A”和“B”都在“ABshare”组中。 The file is create by the "Producer" with permission 0660.该文件由具有权限 0660 的“生产者”创建。

When i run de "Producer" code in user "A", the file is create flawlessly and i can read this when i run the "Consumer" in user "B" but the problem is that i can't delete the file.当我在用户“A”中运行 de“Producer”代码时,文件被完美地创建,当我在用户“B”中运行“Consumer”时我可以读取此文件,但问题是我无法删除该文件。 To delete the file i try using the function "remove ()" http://man7.org/linux/man-pages/man3/remove.3.html要删除文件,我尝试使用函数“remove ()” http://man7.org/linux/man-pages/man3/remove.3.html

When I run the "Producer" and the "Consumer" both in user "A" or in user "B", the "Producer" generate the file and the "Consumer" can read and delete this file.当我在用户“A”或用户“B”中运行“Producer”和“Consumer”时,“Producer”生成文件,“Consumer”可以读取和删除该文件。

Why i can't delete the file when i run the "Producer" and the "Consumer" in diferents users?为什么我在不同用户中运行“生产者”和“消费者”时无法删除文件? I try modify the own of the file from "A" to "B" before delete him using the "Consumer" code, for this I use this code: Change owner and group in c, but i can only change the group of file not the own.在使用“消费者”代码删除他之前,我尝试将文件自己的“A”修改为“B”,为此我使用以下代码:更改 c 中的所有者和组,但我只能更改文件组而不是自己的。

Reading about chown fuction in ths man page: http://man7.org/linux/man-pages/man3/chown.3p.html i find this information: "Changing the user ID is restricted to processes with appropriate privileges ."阅读有关 chown 功能的手册页: http : //man7.org/linux/man-pages/man3/chown.3p.html我发现以下信息:“更改用户 ID 仅限于具有适当权限的进程。”

How I can give to the "Consumer" code the " appropriate privileges " to change the own of file create by the "Producer" in user A when " Consumer" run in "B"?当“消费者”在“B”中运行时,如何为“消费者”代码提供“适当的权限”以更改用户 A 中的“生产者”创建的文件的自身? Or, How I can delete the file created by "Producer" when "Producer" and "Consumer" run in diferrents users?或者,当“生产者”和“消费者”在不同用户中运行时,如何删除“生产者”创建的文件?

Please, Somebody can help me?拜托,有人可以帮助我吗?

Thank you!!!谢谢!!!

Like wildplasser said, all I needed is to give the correct permission to the directory where the files lives.就像wildplasser 所说的那样,我所需要的只是为文件所在的目录提供正确的权限。 In my case, the new permission of directory is 0777.就我而言,目录的新权限是 0777。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM