Failed to open device

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 define by me in condition, but why i am not able to get into the device? Here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
* 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 make me correct where I am on mistake!?
Sindhu
You can get more information on the error from the errno variable, as in the following example:

1
2
3
4
5
6
7
8
9
10
11
#include <errno.h>
#include <string.h>

...

int ret = open("/dev/simulator", O_RDWR);

if (ret < 0) {
  printf("open() failed: %s", strerror(errno));
}
Is /dev/simulator bound to a valid device?
Topic archived. No new replies allowed.