General
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get umask of an existing process

Jose M. del Rio
Frequent Advisor

How to get umask of an existing process

How can I get the umask value of an existing process?
Thanks.
13 REPLIES
James R. Ferguson
Acclaimed Contributor

Re: How to get umask of an existing process

Hi Jose:

You could use 'umask' to set a new value (perhaps the same as the current one) while returning the old value. See: 'umask(2)'.

If this is a shell, simply use 'umask' without arguments to display the current value.

Regards!

...JRF...

Jose M. del Rio
Frequent Advisor

Re: How to get umask of an existing process

Thanks, JRF.
I meant: for any process in the system (other than my shell and this_process).
TTr
Honored Contributor

Re: How to get umask of an existing process

I don't think there is a way to interrogate a running process and extract its umask setting if this is what you are asking. You can set a umask value in the starting shell if the "running process" is started by a shell but there is no guarantee it will be obeyed, internally the process may have been programmed to use its own umask.
Dennis Handly
Acclaimed Contributor

Re: How to get umask of an existing process

It would probably be easier to make sure the correct umask value is set in your process than to try to figure this out.
Any particular process you are interested in?
Dennis Handly
Acclaimed Contributor

Re: How to get umask of an existing process

The umask value doesn't seem to be returned by pstat_getproc(2).
Jose M. del Rio
Frequent Advisor

Re: How to get umask of an existing process

Yes. I also tried that but didn't find the umask value either.
Glance doesn't seem to help either.
I also tried generating a dump with gdb but no luck.

>>>> Any particular process you are interested in?
Yes. The Oracle listener process when using the UTL_FILE package.
According to several Metalink notes (463312.1, 197201.1, 74268.1), the listener just follows the umask value inherited from its parent.
I've traced the system calls made by the listener and it's true:
- it just creates the file with 0666 mask
11:04:22 [oracleBDSC (][16868]{3779834} <-0.000000> open("/u6/sic2/TEMP/JMR12.txt",
O_WRONLY|O_CREAT|O_TRUNC, 0666) [entry]
- it doesnt' explicitly call chmod() or umask() to change permissions
- it just calls umask() to retrieve its value and set it back:
11:04:10 [oracleBDSC (][16868]{3779834} <-0.000000> umask(0777) [entry]
11:04:10 [oracleBDSC (][16868]{3779834} <0.000018> umask(0777) = 022
11:04:10 [oracleBDSC (][16868]{3779834} <-0.000000> umask(022) [entry]
11:04:10 [oracleBDSC (][16868]{3779834} <0.000013> umask(022) = 0777

From the trace we know the file is created 666 - 022 = 644, which is right for us, because other users have to read the file.
The problem is, under some circumstances we are not able to reproduce, the files are created 600 so, if the open(, 0666) mask doesn't change, we assume the listener is running with umask 066 (or 067, 076, 077).
As there are several ways to start a listener:
- directly calling lsnrctl start from an oracle10's ksh shell (thus applying the umask 022 in its .profile)
- through Oracle Enterprise Manager Grid Control (thus appying the umask the OEM agent is running with, 037 in our case)
- in an HP-UX startup script /sbin/init.d... (thus applying the umask 022 in /sbin/rc)
- ...
our plan is:
- to wait till the problem reproduces and tusc again the listener process to get its umask value in that moment
- to file a SR with Oracle.

Any suggestions would be appreciated.
Dennis Handly
Acclaimed Contributor

Re: How to get umask of an existing process

>I also tried generating a dump with gdb but no luck.

I've never seen umask.

>in an HP-UX startup script /sbin/init.d... (thus applying the umask 022 in /sbin/rc)

You may want to change Oracle's rc script to set umask to the way it wants it?
Do you know how that failing listener process was started?

Jose M. del Rio
Frequent Advisor

Re: How to get umask of an existing process

Thanks, Denis.

>>>> You may want to change Oracle's rc script to set umask to the way it wants it?
Sorry, I havenâ t made myself very clear: we do have a startup script that starts the listener at OS startup. I meant that, as any other startup script that doesn't set umask explicitly, it inherits de umask setting at /sbin/rc, according to what I've read at the ITRC forums.

>>>> Do you know how that failing listener process was started?
You hit the bull's eye: that's the correct question to ask.
As I mentioned, there are several ways we can start the listener and, unless we are missing something, we know all of them and what the umask value should be in each case.
Dennis Handly
Acclaimed Contributor

Re: How to get umask of an existing process

>as any other startup script that doesn't set umask explicitly, it inherits the umask setting at /sbin/rc

Yes but if you can't trust it, set it the way you want. Or at least log it.

>we know all of them and what the umask value should be in each case.

Can you use ps(1) to figure out which is the current bad case?
UNIX95=EXTENDED_PS ps -Hef
Jose M. del Rio
Frequent Advisor

Re: How to get umask of an existing process

>>>> Yes but if you can't trust it, set it the way you want. Or at least log it.
Good point.
We have to schedule a programmed halt to install some patches and we'll check that case.

>>>> Can you use ps(1) to figure out which is the current bad case?
I don't get your point.
Dennis Handly
Acclaimed Contributor

Re: How to get umask of an existing process

>>>> Can you use ps(1) to figure out which is the current bad case?
>I don't get your point.

By looking at your process tree, can you figure out how it started? Or is it a demon, so the PPID is 1, init?
You can also add -x to get longer command lines.
Jan Zalman
Advisor

Re: How to get umask of an existing process

Here you are.
Script for 11.11, 11.23 AND 11.31 attached.
Regards
Time and loyalty cannot be bought.
JimUrsetto
Visitor

Re: How to get umask of an existing process

That script works perfectly Jan. Thanks.