Hi.
Idea is to call a function to unload all loaded sfs modules each and every time after a process has been exited/finished.
I need to find out, if a process/program has been exited during the running time of puppy. Want to do this in bash - if possible.
How could this be achieved?
Thanks
(Solved) How to find out if Process/Program was exited?
- LazY Puppy
- Posts: 1934
- Joined: Fri 21 Nov 2014, 18:14
- Location: Germany
(Solved) How to find out if Process/Program was exited?
Last edited by LazY Puppy on Thu 14 May 2015, 00:48, edited 1 time in total.
RSH
"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:
No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:
"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:
No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:
You might use "watch" like this.
When watch terminates, it could call an SFS unload command.
Cheers,
s
Code: Select all
watch -n 1 "ps u -C <process_name>"
Cheers,
s
- LazY Puppy
- Posts: 1934
- Joined: Fri 21 Nov 2014, 18:14
- Location: Germany
Thanks a lot.seaside wrote:You might use "watch" like this.
When watch terminates, it could call an SFS unload command.Code: Select all
watch -n 1 "ps u -C <process_name>"
Cheers,
s
I thought already of using watch, but when I'm entering watch --help into a terminal it gives only to options to me -n and -t. So I'd modified your line (removed <process_name>) and it gave me lot of more options - so I could find -A, since I need to watch all processes, counting them and make a diff using number of processes between to calls.
Currently I'm making the diff of running processes between to calls of watch by echoing results of watch into a text file. Doing a backup of this text file before calling watch again and overwriting the results text file.
Then I'm reading both files (while read LINE etc) and making a diff of counted lines. If counted lines of the backup text file is greater, say number of processes have been decreased, unloading of SFS will start.
I will try to use 'grep -n' or 'wc -l' like don570 has suggested right now in the other topic, to make this 'while read LINE' stuff a little smarter.
---
Edit:
Code 'wc -l' did it and I used at last option -e when calling watch.
Now everything works as intended.
RSH
"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:
No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:
"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:
No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:
Hello, Lazy Schmurf.
"watch" takes constant energy. Simpler to consult the ps database.
If the process is there, it's there, and we do something;if the process
isn't, it isn't, and we do something else.
Something like:
More precise consultation is done with awk, with or without the "!".
Good luck.
musher0
"watch" takes constant energy. Simpler to consult the ps database.
If the process is there, it's there, and we do something;if the process
isn't, it isn't, and we do something else.
Something like:
Code: Select all
process="opera"
[ "`ps | grep $process`" = "" ] && echo "Oh, the $process is not there. Don't do anything!" || echo "Wow, the $process is ongoing. Do something!"
More precise consultation is done with awk, with or without the "!".
Code: Select all
ps | awk '$4 ~ /opera/
musher0
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
- LazY Puppy
- Posts: 1934
- Joined: Fri 21 Nov 2014, 18:14
- Location: Germany
I have tested this with some apps that are not installed and so not running. It returns all the time: "Wow, the ProcessHere is ongoing. Do something!"process="opera"
[ "`ps | grep $process`" = "" ] && echo "Oh, the $process is not there. Don't do anything!" || echo "Wow, the $process is ongoing. Do something!"
This complains a ---> missing `''ps | awk '$4 ~ /opera/
Sorry...
...both of them aren't of any use over here (bash 4.1)
RSH
"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:
No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:
"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:
No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:
Well, don't use them!LazY Puppy wrote:I have tested this with some apps that are not installed and so not running. It returns all the time: "Wow, the ProcessHere is ongoing. Do something!"process="opera"
[ "`ps | grep $process`" = "" ] && echo "Oh, the $process is not there. Don't do anything!" || echo "Wow, the $process is ongoing. Do something!"
This complains a ---> missing `''ps | awk '$4 ~ /opera/
Sorry...
...both of them aren't of any use over here (bash 4.1)
Thanks anyway for revising me.
The 1st command line contained an oversight. It should have read:
Code: Select all
process=opera;echo;[ "`ps | grep $process | grep -v grep`" = "" ] && echo "Oh, $process is not running. Don't do anything!" || echo "Wow, $process is running. Do something!";echo
The 2nd command line contained a typo. It should have read:
Code: Select all
ps | awk '$4 ~ /opera/'
However, I think that the bash version has nothing to do with it.
BFN.
musher0
- Attachments
-
- process_running_OR_not_2015-05-14.jpg
- Corrected line now works when > grep -v grep < is added.
Sorry about the oversight. - (34.85 KiB) Downloaded 59 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)