ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If you lsof /dev/dsp, you will get all processes that have the sound device open. This tells you if sound is opened for recording too. It will not tell you if it is currently getting read() or write(). Those issues probably don't really matter for your app, though.
Distribution: Slack, FreeBSD,NetBSD, OpenBSD, Open Solaris, Minix
Posts: 172
Original Poster
Rep:
Thanks for the reply. Though that won't work for my app. I need to know if audio has been stopped for any reason, be it paused / stopped by a user or if a live stream is dropped.
If you ls -lu /dev/dsp, it shows the last access time. The problem here is that the number is that the granularity is too big, but I know I can write a simple C app that would be able to get you an unformatted access timestamp in seconds quite easily. There might be a standard program to get that info, but I don't know from the top of my head what it is.
Distribution: Slack, FreeBSD,NetBSD, OpenBSD, Open Solaris, Minix
Posts: 172
Original Poster
Rep:
The stat command gives me the access time in seconds, however using the stat command changes the access time of the file, and there's no preserve flag.
The access time is probably being updated because it is following the link. I noticed that stat times weren't useful on the device itself. The 10 second C app I did that doesn't follow links didn't work because the value would be updated too late. I suppose that makes sense because that is how reader-writer locks work. Turns out ls -lu has the same problem as stat. Thinking further, access time might be completely the wrong idea.
The only way to really know whether read() and write() is happening or not may be to catch the system call, sort of like how installwatch does it to track installations. I don't really want to go there, but it is a potential solution.
#!/bin/sh
dialog --yesno "Do you hear sound coming from the speakers?" 10 30
if [[ $?== 0 ]]; then
#... sound playing...
else
#... sound not playing...
fi
Sorry, couldn't resist, you did ask for a _simple_ way...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.