SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2012-11-26 09:23:07

Obadobo
Member
Registered: 2011-06-12
Posts: 36
Website

Script to check if process is running (oss4) [solved]

This is something I've searched on various occasions and haven't been able to follow the answers and adopt them for my purposes.

I'm using oss instead of alsa.  I won't go into the reasons for that here, but one of the shortcomings of oss is it doesn't survive being suspended, so you need to start it after suspending.  What I would like is to work out a script that checks every couple of minutes whether oss is running and starts it if not, to save me the hassle if I forget to start it.  The command to start oss is

sudo /etc/init.d/oss start

and I have NOPASSWD set in the sudoers file.

As always, any help appreciated

Last edited by Obadobo (2012-11-28 17:38:39)

Offline

Be excellent to each other!

#2 2012-11-26 11:34:37

rebornmechanics
#! CrunchBanger
Registered: 2012-11-05
Posts: 154

Re: Script to check if process is running (oss4) [solved]

You can check for a process with pidof or pgrep. If you want your script to run in intervals you might want to look into cron/anacron. Can't really give you any more concrete advice at this time as I'm at work right now and don't have access to a #! machine where I could test this. If you google how to do it with pidof and how to use anacron I'm sure you'll figure it out in no time.

Offline

#3 2012-11-26 12:24:28

Obadobo
Member
Registered: 2011-06-12
Posts: 36
Website

Re: Script to check if process is running (oss4) [solved]

Thanks, rebornmechanics.  I've never got my head round anacron - I'll have another google, but if anyone can point me to a really clear howto with examples that would be great.

The next problem is, though that oss doesn't seem to show as a process, even if it's running

ps aux | grep 

only returns

19894  0.0  0.0   3524   800 pts/1    R+   12:30   0:00 grep -i oss

even though it is running, as shown by:-

sudo /etc/init.d/oss start
Starting Open Sound System: OSS is already loaded.

So that makes me even more mystified about how I would write a script which depends on whether it was running.

Last edited by Obadobo (2012-11-26 12:34:05)

Offline

#4 2012-11-26 12:35:13

xaos52
The Good Doctor
From: Planet of the @s
Registered: 2011-06-24
Posts: 4,602

Re: Script to check if process is running (oss4) [solved]

Using alsa myself, I do not know what '/etc/init.d/oss start' does.
If it is like alsa, it just restores some volume levels and stops. So it might be impossible to check whether it is running or not. Perhaps '/etc/init.d/oss status' outputs something useful and could be run periodically?

Last edited by xaos52 (2012-11-26 12:36:37)

Offline

#5 2012-11-26 12:44:06

Obadobo
Member
Registered: 2011-06-12
Posts: 36
Website

Re: Script to check if process is running (oss4) [solved]

At the moment I'm just going with a startup script of

#! /bin/bash

while true
do
sleep 300
sudo /etc/init.d/oss start
done

Offline

#6 2012-11-26 13:01:56

Obadobo
Member
Registered: 2011-06-12
Posts: 36
Website

Re: Script to check if process is running (oss4) [solved]

xaos52 wrote:

If it is like alsa, it just restores some volume levels and stops. So it might be impossible to check whether it is running or not.

  Yes, I think you are right.

Perhaps '/etc/init.d/oss status' outputs something useful and could be run periodically?

  There is  ossinfo but it doesn't seem to report whether oss is running or not!  I'm going to edit the subject because it seems that the problem is more specific to oss than I had anticipated

Offline

#7 2012-11-26 13:44:47

el_koraco
#!/loony/bun
From: inside Ed
Registered: 2011-07-25
Posts: 4,749

Re: Script to check if process is running (oss4) [solved]

Offline

#8 2012-11-26 14:28:55

Obadobo
Member
Registered: 2011-06-12
Posts: 36
Website

Re: Script to check if process is running (oss4) [solved]

er - that seems to stop pm-suspend from working.  But I have as /etc/pm/sleep.d/30oss4-pm the following


#!/bin/sh
#
# 99oss4-pm: Restart sound on suspend/resumt

case "$1" in
	hibernate|suspend)
		# We need to force unload in order
		# to quit applications that are using oss4..
		if which invoke-rc.d >/dev/null 2>&1; then
			invoke-rc.d oss4-base force-unload
		else
			/etc/init.d/oss4-base force-unload
		fi
		;;
	thaw|resume)
                if which invoke-rc.d >/dev/null 2>&1; then
                        invoke-rc.d oss4-base start
                else
                        /etc/init.d/oss4-base start
                fi
		;;
	*) exit $NA
		;;
esac

Last edited by Obadobo (2012-11-26 14:32:17)

Offline

#9 2012-11-28 17:37:42

Obadobo
Member
Registered: 2011-06-12
Posts: 36
Website

Re: Script to check if process is running (oss4) [solved]

This is how I solved it:-

#! /bin/bash 


sleep 5 && sudo /etc/init.d/oss start &
sudo pm-suspend

My keybind for suspend links to this script.  So the computer waits 5 seconds to launch oss.  Meanwhile it goes to sleep, so the 5 seconds finish after it wakes up.  Seems to work fine  smile

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo