Thread: works with devices in /dev/*

  1. #1
    Registered User
    Join Date
    Aug 2020
    Posts
    1

    works with devices in /dev/*

    hi,i am new in c programming and lately i have been wondering:

    if in linux, all devices are considered as files, why some devices like usb webcam connected to linux machine are as not simple to open and use as opening a normal file in a c program?
    ex: i connected a usb webcam on my linux(ubuntu) laptop and i tried to open it and read from it as normal file but i could work, and i wonder why i can open a camera as normal file and read from it if linux consider it as a file. thank you.

    ps: i apologise in advance if i asked a stupid question .

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,626
    i tried to open it and read from it as normal file but i could [not get it to] work
    What exactly did you do? (Post code/script.)
    How exactly did it not work?
    A little inaccuracy saves tons of explanation. - H.H. Munro

  3. #3
    Registered User
    Join Date
    Nov 2018
    Location
    Amberg in upper palatinate, Bavaria
    Posts
    66
    May be you need to have root Permissions to use usb-devices.
    For example if you want to use an usb-stick with windows emulated on qemu-kvm
    you need first to login as superuser.
    Then, start terminal and type 'lsusb' to detect what for a bus and what for a device
    you must use to access an usb-stick with an emulated operating system.

    If you want to get only informations you can use 'lsusb' without root permissions.

    I don't know if you can change the permissions with chmod for the device, but it is
    possible that the permissions will change to the former status after a new start of
    the system.

  4. #4
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Quote Originally Posted by j3ph View Post
    hi,i am new in c programming and lately i have been wondering:

    if in linux, all devices are considered as files, why some devices like usb webcam connected to linux machine are as not simple to open and use as opening a normal file in a c program?
    Yep.. use open() to get a file desciptor and...

    Quote Originally Posted by j3ph View Post
    ex: i connected a usb webcam on my linux(ubuntu) laptop and i tried to open it and read from it as normal file but i could work, and i wonder why i can open a camera as normal file and read from it if linux consider it as a file. thank you.
    ... there is a special syscall to deal with devices: ioctl(), to send "commands" to control the device. Those commands are device dependent...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Programming for Devices
    By legit in forum Tech Board
    Replies: 2
    Last Post: 01-29-2009, 06:02 AM
  2. devices
    By pastitprogram in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2008, 04:41 PM
  3. Checking for devices...
    By SirCrono6 in forum C++ Programming
    Replies: 2
    Last Post: 03-28-2005, 09:07 PM
  4. Tracking Devices, GPS and etc.
    By Liger86 in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 05-14-2003, 05:12 AM
  5. About those devices..
    By Unregistered in forum C++ Programming
    Replies: 0
    Last Post: 03-14-2002, 04:30 AM

Tags for this Thread