1

I am trying to write on the /dev/simulator file. I have created this device by using:

  • # mknod /dev/simulator c 60 0
  • # chmod 666 /dev/simulator
  • # ls -l /dev/simulator
  • crw-rw-rw- 1 root root 60, 0 2012-05-22 19:22 /dev/simulator

I am trying to open this device and write something on it, but getting an error:

application: Simulator opening failed

which is defined by me in condition, but why am I not able to get into the device? Here is my code:

/*
* Some Other Code *
*/

static int simDev;
simDev = open("/dev/simulator", O_RDWR);
if(simDev<0) {
 printf("application: Simulator opening failed.\n");
 exit (1);
}
else 
 printf("Device opened successfully.");

signal(SIGIO, signal_handler);
pid_t pid;
pid = getpid();
write(simDev, &pid, 4);

/*
* Some Other Code *
*/

close(simDev);

Can anyone please help me correct my mistake?

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
Raheel
  • 133
  • 2
  • 5
  • 10

1 Answers1

3

You don't have a kernel module that defines the other end of that device.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • kernel Module is also written and its compiling fine. – Raheel May 23 '12 at 06:11
  • struct file_operations sim_fops = { write : sim_write, release : sim_release, open : sim_open, }; int sim_open(struct inode *inode, struct file *filp) { /*sucess*/ return 0; } int sim_release(struct inode *inode, struct file *filp) { /*sucess*/ return 0; } ssize_t sim_write(struct file *filp, char *buf, size_t count, loff_t *f_pos) { int *id; pid = copy_from_user (&id, buf, sizeof(id)); if(pid < 0) printk("Unsucess in accessing user pid %d", pid); else printk("copied pid from user : %d", pid); return count; } – Raheel May 23 '12 at 06:13
  • If i use to check the device via : cat /dev/simulator ---- then it gives me output like this: cat: /dev/simulator: No such device or address – Raheel May 23 '12 at 06:49
  • Likely the module has not been loaded, or is non-functional. – Chris Stratton Feb 17 '14 at 21:31