Click here to Skip to main content
15,886,791 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to get a list of all signals in linux that are string so i can compare the user input with existing signals if true go on with the program if false end

What I have tried:

i tried to do this:
Python
lista=[]
for i in signal.valid_signals()
{
lista.append(i)
str(i).strip(<Signals.:>)
}
print(lista)

that didn't work
Is there a way to create a fast list of all linux signals without writing them myself into a list?
Posted
Updated 26-Jun-21 9:14am

Well, maybe homework but here is quick and dirty, you can improve:
import signal
valid_signals = signal.valid_signals()
arr=str(valid_signals).split(',')
for i in range(0, len(arr)):
        start=arr[i].find("Signals")+8
        end=arr[i].find(":")
        if(end>0):
                print(arr[i][start:end])
 
Share this answer
 
Your python3 version must be 3.8 or above to support signal.valid_signals()
Then this will give you an array:

import signal
 
valid_signals = signal.valid_signals()
print(valid_signals)
print(len(valid_signals))
arr=str(valid_signals).split(':')
print(arr)


The array will look something like these first few lines:
['{<Signals.SIGHUP', ' 1>, <Signals.SIGINT', ' 2>, <Signals.SIGQUIT', ' 3>, <Signals.SIGILL', ' 4>, <Signals.SIGTRAP', 


You should be able to parse as needed.
 
Share this answer
 
Comments
Member 15262726 26-Jun-21 14:19pm    
So yeah this does create a list but i'm trying to get rid of everything but SIGQUIT,SIGILL ect. and strip isn't helping here any solution for that?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900