根據(jù)運(yùn)行的環(huán)境,操作系統(tǒng)可以分為桌面操作系統(tǒng),手機(jī)操作系統(tǒng),服務(wù)器操作系統(tǒng),嵌入式操作系統(tǒng)等。 
答案0 : (得分: 14)
Roosmaa的答案是正確的-mkfifo()僅調(diào)用mknod()創(chuàng)建一個(gè)特殊文件,而FAT32不支持它.
作為替代方案,您可能要考慮使用Linux的“抽象名稱(chēng)空間” UNIX域套接字. 它們應(yīng)大致等效于命名管道. 您可以按名稱(chēng)訪問(wèn)它們,但它們不是文件系統(tǒng)的一部分,因此您不必處理各種權(quán)限問(wèn)題. 請(qǐng)注意,套接字是雙向的.
由于它是一個(gè)套接字,因此您可能需要INTERNET權(quán)限. 不確定.

以下是客戶端/服務(wù)器示例代碼的一小部分:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stddef.h>
#include <sys/socket.h>
#include <sys/un.h>
/*
* Create a UNIX-domain socket address in the Linux abstract namespace.
*
* The socket code doesnt require null termination on the filename, but
* we do it anyway so string functions work.
*/
int makeAddr(const char* name, struct sockaddr_un* pAddr, socklen_t* pSockLen)
{
int nameLen = strlen(name);
if (nameLen >= (int) sizeof(pAddr->sun_path) -1) /* too long? */
return -1;
pAddr->sun_path[0] = \0; /* abstract namespace */
strcpy(pAddr->sun_path+1, name);
pAddr->sun_family = AF_LOCAL;
*pSockLen = 1 + nameLen + offsetof(struct sockaddr_un, sun_path);
return 0;
}
int main(int argc, char** argv)
{
static const char* message = hello, world!;
struct sockaddr_un sockAddr;
socklen_t sockLen;
int result = 1;
if (argc != 2 || (argv[1][0] != c && argv[1][0] != s)) {
printf(Usage: {c|s}\n);
return 2;
}
if (makeAddr(com.whoever.xfer, &sockAddr, &sockLen) < 0)
return 1;
int fd = socket(AF_LOCAL, SOCK_STREAM, PF_UNIX);
if (fd < 0) {
perror(client socket());
return 1;
}
if (argv[1][0] == c) {
printf(CLIENT %s\n, sockAddr.sun_path+1);
if (connect(fd, (const struct sockaddr*) &sockAddr, sockLen) < 0) {
perror(client connect());
goto bail;
}
if (write(fd, message, strlen(message)+1) < 0) {
perror(client write());
goto bail;
}
} else if (argv[1][0] == s) {
printf(SERVER %s\n, sockAddr.sun_path+1);
if (bind(fd, (const struct sockaddr*) &sockAddr, sockLen) < 0) {
perror(server bind());
goto bail;
}
if (listen(fd, 5) < 0) {
perror(server listen());
goto bail;
}
int clientSock = accept(fd, NULL, NULL);
if (clientSock < 0) {
perror(server accept);
goto bail;
}
char buf[64];
int count = read(clientSock, buf, sizeof(buf));
close(clientSock);
if (count < 0) {
perror(server read);
goto bail;
}
printf(GOT: %s\n, buf);
}
result = 0;
bail:
close(fd);
return result;
}
答案1 : (得分: 8)
/ sdcard的默認(rèn)文件系統(tǒng)是FAT32,它不支持命名管道.

在非root用戶的設(shè)備上,您可以嘗試創(chuàng)建這些管道的唯一可能位置是應(yīng)用程序數(shù)據(jù)目錄/data/data/com.example/. 注意: 您不應(yīng)該對(duì)此值進(jìn)行硬編碼,請(qǐng)使用Context.getApplicationInfo(). dataDir.
但是請(qǐng)注意,每當(dāng)用戶使用Apps2SD或Google正式實(shí)現(xiàn)此支持時(shí)創(chuàng)建命名管道,都需要確保用戶知道該應(yīng)用程序無(wú)法存儲(chǔ)在vfat文件系統(tǒng)中.
答案2 : (得分: 1)
我要附加接受的答案:

1)我可以使用此方法在Android應(yīng)用程序的兩個(gè)本機(jī)模塊之間連接套接字.
2)write()應(yīng)該處于循環(huán)中,因?yàn)樗赡懿粫?huì)寫(xiě)入第一個(gè)請(qǐng)求的全部?jī)?nèi)容. 例如,它應(yīng)如下所示:
void *p = buffer;
count = 0;
while ((count += write(clientSock, buffer, num_bytes - count)) < num_bytes)
{
if (count < 0)
{
close(clientSock);
errCode = count;
break;
}
p += count;
}
上面顯示的錯(cuò)誤處理是不夠的,因?yàn)橐恍╁e(cuò)誤代碼僅意味著要重試. 請(qǐng)參閱編寫(xiě)文檔.

答案3 : (得分: 1)
還有/ sqlite_stmt_journals(我們將其用于測(cè)試,我不知道此目錄可以在操作系統(tǒng)更新中保留多長(zhǎng)時(shí)間)
如果您需要IPC,最佳做法是使用Binders
如果只需要線程間通信,則可以通過(guò)JNI使用未命名的管道(可以正常工作)
答案4 : (得分: 0)
如果您使用Java編寫(xiě)此代碼創(chuàng)建命名管道,則應(yīng)使用PipedInputStream和PipedOutputStream.
本文來(lái)自本站,轉(zhuǎn)載請(qǐng)注明本文網(wǎng)址: http://www.pc-fly.com/a/jisuanjixue/article-288040-1.html
|