Hello all, I have an AIX 6.1 machine and i am having a hard time to figure out how i can make exec work inside a loop. i have a while loop which calls a case statement in it. when the user chooses a specific choice, it calls a script using exec. The reason that i use exec to run this script is because through this script it can open many windows so i do not want to have a lot of ksh running on my server. the problem is that when the user exits the script then it exits the shell. it does not go to the next line of the loop. Is there a way to have both the loop running and call the exec for executing my script or is it impossible? Thank you
exec turns the current shell into the called processes, i.e. the current shell is gone.
Simply run the whatever program without exec !
The shell will wait until it exits; this is the behavior you intend.
the problem is that if i run this program without exec, if a user runs 3 programs from the initial program then i see double processes on the server. 3 for the programs and another 3 that is for ksh because it starts a new shell. and this is what i am trying to avoid. there is no way for lets say exec call 2 programs? so when the first program will finish then it will call my second program which will re-launch the loop again.
Is your system so overloaded that fork fails? If not, why fret? If so, you've got a bigger problem than a few instances of ksh.
Regards,
Alister
well we are talking about a lot of users connecting to the system so it is better to try to minimize the load on it whenever possible. its better to build something right from the beginning and have more chances of keeping it up and running without problems rather just do something if is something happens then you try to find out what can you do
Impossible. exec only accepts a single command.
If you believe that I am mistaken, refer yourself to the documentation of the exec system call interface which is wrapped by the exec shell builtin.
If you aren't sure about your script, post it. Vague concerns about instances of ksh in the process list is not a good reason to overcomplicate an implementation.
Regards,
Alister
exec reduces the number of processes by replacing your shell with something else. Once you exec, your shell is gone.
ok thank you all for your replies. the main reason i created this post was to find out if it could possible to run 2 commands/scripts using exec cause i couldnt find something like that when i searched about it. so it is clear now that exec just executes one command and thats it. its fine i will let it work like it is now and the users will have to reconnect again. this is no problem. i was just curious if i could provide them the possibility of getting back to their session in a way. thank you all