Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm a long time dev but linux newbie. I've been building this (http://tryperl.com) to learn linux. So, my question is just about some *nix stuff I don't fully grok.

One of the things I want to do is run the generated script (in my application) as a limited user. So I create a limiteduser . Then I can set say fork limits like this : limiteduser hard nproc 300.

Is this then the right way of running a script as limiteduser :

sudo -u limiteduser perl myscript.pl

Secondly, what if I had concurrent requests that forked and executed and ran the above code simultaneously, with different scripts. Would that cause problems? I heard it would, if two processes ran on the same user or something?

Specifically I'm running on ubuntu but I assume this applies to any *nix distro?


Update: Also, I plan to use Time::Out to timeout a script if it takes too long so ideally I should have a limited number of processes running.

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

First, sudo is a good way to run a script as a limited user.

Second, whether there will be problems running more than one instance of the script at the same time will depend on what the script actually does. It has (usually) nothing to with whether the various instances are run by the same user - instead, you need to consider whether the script e.g. tries to edit a file, in which case two instances might try to edit the same file at the same time, which may leave the file in an unexpected state.

Also, of course if you are limiting how many processes the user is allowed to run, or how much memory it's allowed to consume, then at some point you may run into the limit and the script won't be able to do what you want. But that's a feature of the whole limiting system. (If you don't have limits, then a badly written program may cause your entire system to grind to a halt. But again, that is because of how the program is written, not because of who runs it (except that if you run the program as root then it's a lot easier to break things, which is why it's good that you have the limited user running things).)

share|improve this answer
    
Thanks for your answer. (1) I plan to prevent any file reads/write inside the script, so I should be ok then? (2) I will time out if the script takes too long so ideally there should only be a limited number processes running on the same user. I updated my question. –  gideon Feb 19 '13 at 11:03
    
(1) Yes, you should be OK. (2) Also shouldn't be a problem then. When you start trying the things out, you might want to do a recurring ps -f -U limiteduser to see what processes are running. Also, the top command should be of interest. –  Jenny D Feb 19 '13 at 11:12
add comment

Regarding your first point, this is a way to do it! It is correct.

About the second point, Unix/Linux can cope with many concurrent processes much like any multi-process OS. When it cause problems it is due to resource contentions usually. So are all your processes going to access one file, or one file system on a slow storage, or one IPC resource with a big fat lock, etc. So basically the concurreny problems you would have on OS X or Windows, have similarities in the Linux/Unix worlds.

share|improve this answer
    
+1 hey Thanks for your answer. I plan to prevent any file read/writes inside the script.pl so I should be ok right? –  gideon Feb 19 '13 at 11:04
    
There are various other resources than files. You can have network, memory, ... I wanted to state that Linux is a multi-process, multi-threaded OS so it will behave fairly well with many processes. But this all depends on so many factors (how many forks per period, how many process wake up per period, etc.) that your question is too generic to answer with yes or no. What I can tell you is that you can run a multi process program on Linux, you won't break anything. –  Huygens Feb 19 '13 at 18:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.