I am trying to make a c program where i am using mknod command like
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
char info[50];
main() {
int fdr;
int rc = mknod("testfile",'b',0);
if(rc<0) {
perror("Error in mnod");
}
fdr=open("testfile",O_RDONLY);
read(fdr,info,50);
printf("\n Received message=%s",info);
printf("\n");
}
And do some stuff. It works well on Red Hat system, but fails on ubuntu giving error invalid argument.
'b'
is not a very sensible argument for mknod here.mknod
's argument should be a bitwise OR of a permissions mask (modified by umask) andS_IFREG
(for a regular file) orS_IFIFO
(for a FIFO). For example: