Programming :: Use Of Dlopen When Forking Many Similar Processes?

Dec 27, 2010

I am building a queue system (in C on CentOS 5) where each directory queue has a number of process instances 'watching' it. I have a root-permission queue supervisor process which does all the forking, and the instance processes give up root as their first action. For max security each queue is accessible to a different set of users and groups.

I need to keep the RAM requirements as low as possible, so I am relying heavily on copy-on-write (since all memory writes are to shmget() shared memory)

Each process presently dlopen's the libraries it requires after fork, but I'm wondering if I would gain by performing the dlopen before forking a number of instances which all require the same libraries.

Any pointers to mid-level tutorials on dlopen and fork internals would be most appreciated: this is about my third post anywhere since I converted to Linux, but I just can't find the answer to this anywhere online.

View 3 Replies


ADVERTISEMENT

Programming :: Dlopen And Undefined Error ?

Mar 22, 2010

I've been told to move my code from MFC to linux platform, and so I did, trying to keep as much as I can on the way, now, I had a dll and application, the application I rewrote all anew while the dll I only made changes so it'll be an ".so" file, now, when I try to link using "dlopen", I get the message "undefined symbol: _ZN5ImageC1EiiPh", now, Image is a class in the DLL, which even makes its own ".o" file for the DLL itself. I just can't understand why it happens. I use Image in functions which are not in Extern "C", but the functions I want to use don't use it. Also, I have many globals in the DLL, (because that's how the DLL was written in the past) but none of them is Image...

Is the problem with the fact I include a c++ class in the DLL? How can I solve such a problem? I tried messing with how I link it, but I think that's not the issue here.

I use g++ and -rdynamic --export-dynamic -ldl -lrt for the application

and for the dll I use -shared -Wl,-soname, and -lm, and for the .o files of the dll -Wall -fPIC (although for some reason it doesn't let me do it through the makefile and I needed to do that by hand, which was a little weird. I put it in tag, I put it in line, but it still did nothing...

View 4 Replies View Related

Programming :: Segmentation Fault After Second Dlopen() Attempt?

Feb 7, 2010

The game is quite old (2002!) and I'm trying to mod the old version of it (1.02a), the jk2ded server linux binary.The game engine loads my mod's .so file which I compiled using:

Code:

gcc -shared -static -g -fPIC g_syscalls.c common.c main.c -o out/jk2mpgamei386.so
So whilst launching the server for the first time, it loads the .so file using dlopen() without problems and the output is:

Code:

Loading dll file jk2mpgame.
Sys_LoadDll(/web/web11/jk2/base/jk2mpgamei386.so)...
Sys_LoadDll(jk2mpgame) found **vmMain** at 0xb2ed9413
Sys_LoadDll(jk2mpgame) succeeded!
[ NT's Fix ] GAME_INIT

and then it works correctly until I try to change the map the server is on currently.When a map changes on the server,the .so file has to be unloaded.After unloading with dlclose() without errors, when the new map is launched the engine tries to reload the .so into the memory with dlopen() but fails:

Code:

map_restart 0
Cvar_Set2: sv_serverid 78710500
==== ShutdownGame ====

[code]....

View 3 Replies View Related

General :: About Real UID And Forking?

Feb 13, 2010

I'm thinking of designing a software that may need to change the current user to a normal user if run as root. But from what i've read, you can still switch back to root if you were root in the first place (meaning, the real UID is 0). I'd like to make this impossible. I think the solution is forking but i'd like you to confirm this.

My question is, does the real UID of the children is the effective UID of the parent at the time the fork is done? My manual lists what's inherited from the parent but doesn't states this. I'd like an answer about Linux kernel and about Unices in general (i'd like to make it at least POSIX-portable)

View 2 Replies View Related

Software :: Forking A Process Into A New Terminal?

Mar 3, 2011

I am trying to create two processes , a parent process and a child process where each of them have their respective CLI. At any point, the user should be able to switch between the CLI of the parent and child processes. I could find three possible approaches to the problem

1) fork the child process into a new terminal

2) activate the CLI of only the process which is currently in the foreground.

3) Write a script (.bashrc triggers this script on login) to start the two processes separately in two different terminals, such that the second process is triggered once the first process reaches a certain stage in execution.

The first approach probably requires the controlling terminal of the child process to be changed. Can this be achieved ? The second approach will require for the process (parent/child) to itself to know everytime it is put in background / foreground so that its CLI operations can be suspended/resumed respectively. Is this possible? Can a script start programs in a new terminal other than the one it is running in?

View 2 Replies View Related

Programming :: Get Similar Results Using Both Gcc And G++

Mar 7, 2011

consider these lines of code and their outputs:

[CODE]
int C = 0;
fprintf(stdout, "
(C, ++C) Bef = %d, Aft = %d
", C, ++C);
fprintf(stdout, "(C++, C) Bef = %d, Aft = %d
", C++, C);

[Code].....

The only one that looks right to me is the second one. I get similar results using both gcc and g++.

View 4 Replies View Related

Software :: Error - Dlopen(),dlsym(),dlclose() ?

Jun 30, 2011

I was having an issue with dlopen(),dlsym(),dlclose() in my program. it is giving an error: undefined reference to dlopen,dlsym,dlclose

I know till here that this error occurs when we do not include the required header file or if it does not find the definiton.

But i included the required headerfile #include <dlfcn.h> even then i could not get rid of these errors. i wrote a new c-code t check its functionality, it worked there but when I'm using those functions in another program, which is a part of a makefile, it is giving this undefined reference error.

View 3 Replies View Related

Programming :: Possible To Make Application Module Similar To LKM?

Feb 8, 2011

Is it possible to create a loadable module for a C app that could be loaded into the app in runtime from a CLI or web interface?I would like the code to handle a particular type of structure to be "swappable" for lack of a better term. This would allow different modules to be used based on the users wants without having to mess with code. A different module could be downloaded into the application directory then loaded. Basicaly the code would be handed a pointer process it then return it.

View 2 Replies View Related

Programming :: How To Allocate Region Of Memories Which Similar VirtualAlloc?

May 21, 2011

I was looking for a method of allocating memories on Linux which similar VirtualAlloc on Windows.Requirements are:

1. Size of memories block to allocate is 2^16.
2. Address of memories block is larger than 0x0000ffff
3. Address of memories block must have last 16 bits are zero.

On Windows because lower limit of application address (lpMinimumApplicationAddress) we have (2) obvious right. From (1), (2) and system rules we also achieved (3).

View 2 Replies View Related

Programming :: Implement Two Periodical Processes In C++?

Jul 28, 2010

I am doing real time programming in C++, under Linux. I have two processes, let me say A and B. A process is being started periodically, every 5ms. B process is being started every 10ms. The process A is doing data processing. The process B is reading that data and displays it. I am confused about how to run periodically processes. The problem is that the period of process A should be as much as it is possible accurate (5ms). For the process B it isn't so important. I have created independent processes, each in one .cpp file, and I am starting them from bash file. Is that OK? I don't have to make child processes in order to have parallel processes?

View 1 Replies View Related

Programming :: Measure Time Of N Processes?

Oct 24, 2010

how can I measure time of N processes and N threads and then compare this time to prove that threads are faster than processes. understanding C code, or also for some good way to measure time of N processes and N threads for C.

View 5 Replies View Related

Programming :: Different Processes Using Same File Object

Sep 29, 2009

I have 2 completely different processes A and B (they do not have any relationship) suppose A opens a file with file descriptor 4 and B opens another file with file descriptor 5

Can process A use the fd 5 (i.e using the file object of processs B) by any means..if suppose i let the fd 4 of process A to point to the file object of process B(fd 5) will it work? is it safe?

View 3 Replies View Related

Programming :: How To Kill Zombie Processes

Dec 3, 2010

I have my code with my fork in a server and each time a client connects one more process is created. i use this code for the handling of zombies

void sig_chld(int signo){//Diadikasia gia tin diagrafi twn 'zombies'
signal( SIGCHLD, sig_chld );//signal gia ton entopismo tou zombie
pid_t pid;

[code]....

but i need the server to kill each zombie after the client is disconnecting and not to have to press ctrl+c

View 1 Replies View Related

Programming :: Switch Between Processes When Debugging With Gdb?

Feb 11, 2011

How to switch between processes when debugging with gdb?

View 2 Replies View Related

Programming :: Perl To Kill Off Some Processes?

Nov 18, 2010

how to even start this Perl script. I have the following processes:

Command used to get this info:

ps aux --forest | grep -e process_name -e ksh | awk '{if ($1 == "user1" && $1 != "root" && $1 != "UID" && $1 != "xfs" && $1 != "mfg" && $1 != "mfgnet") print $0}'

Processes

user1 2819 0.0 0.0 4272 612 ? S Nov17 0:00 \_ -pksh-ksh
user1 2820 0.0 0.0 64956 1584 pts/833 Ss+ Nov17 0:00 \_ -ksh

[code]....

I need a way to kill off the pids 2819, 2820 because they do not have a process tied to them like pids 2918, 2922 and 6657. The way it works is peek shell (pid 2918)is opened then it starts a ksh (pid 2922) session then from there the end user runs a command (pid 6657).

View 7 Replies View Related

Programming :: Bash Script To Find And Remove Similar Lines From Multiple Files?

Jun 5, 2009

I want to remove duplicate or multiple similar lines from multiple files. I.e. if I have four files file1.txt file2.txt file3.txt and file4.txt and would like to find and remove similar lines from all these files keeping only one line from these similar lines. I only that uniq can be used to remove similar lines from a sorted file.

View 9 Replies View Related

Programming :: Memory Optimization For Child Processes?

Sep 6, 2010

I work on Linux for ARM processor for cable modem. There is a tool that I have written (as the job demands) that sends/storms customized UDP packets using raw sockets. I form the packet from scratch so that we have the flexibility to play with different options. This tool is mainly for stress testing routers.

The details are here.

I actually have multiple interfaces created. Each interface will obtain IP addresses using DHCP. This is done in order to make the modem behave as virtual customer premises equipment (vcpe).

When the system comes up, I start those processes that are asked to. Every process that I start will continuously send packets. So process 0 will send packets using interface 0 and so on. Each of these processes that send packets would allow configuration (change in UDP parameters and other options at run time). Thats the reason I decide to have separate processes.

I start these processes using fork and excec from the provisioning processes of the modem.

The problem now is that each process takes up a lot of memory. Starting just 3 such processes, causes the system to crash and reboot.

I have tried the following:- 1-I have always assumed that pushing more code to the Shared Libraries will help. So when I tried moving many functions into shared library and keeping minimum code in the processes, it made no difference to my surprise.

2-I also removed all arrays and made them use the heap. However it made no difference. This maybe because the processes runs continuously and it makes no difference if it is stack or heap?

3-I suspect the process from I where I call the fork is huge and that is the reason for the processes that I make result being huge. I am not sure how else I could go about. say process A is huge -> I start process B by forking and excec. B inherits A's memory area. So now I do this -> A starts C which inturn starts B will also not help as C still inherits A?. I used vfork as an alternative which did not help either. I do wonder why.

reduce the memory used by each independent child processes.

View 1 Replies View Related

Programming :: Creating Child Processes In A Script?

Oct 14, 2010

the wrong part of the forum but basically im working on a project and getting no where what so ever and i was wondering if i could get your help. Basically i have to create two scripts do:

The parent script which is going to:
o spawn several child processes.
o keep track of the progress of the child processes.

[code]...

View 1 Replies View Related

Programming :: How Do You List Processes - Get A Process's Std - In|out|err - Stream

Jun 3, 2011

How do you list processes, get a process's std(in|out|err) stream, or wait until a process is finished in C?

View 3 Replies View Related

Programming :: Ipc Between Parent And Child Processes Using Pipe?

Oct 13, 2010

If a process forks its child and communicate with the child using pipe, do closing the write end of the pipe and terminating the writing process have the same effect?

View 3 Replies View Related

Programming :: IPC Command - Does Not Shows The Processes That Communicating To Each Others

Sep 28, 2010

The ipcs command shows the facilities of IPC in Linux, but it does not shows the processes that communicating to each others. How can I list the processes, which is currently communicating in IPC ?

View 6 Replies View Related

Programming :: Kill Script Kills Too Many Processes?

Oct 21, 2010

User 1 and User 2 each start a mono process with sudo:

"sudo mono user1.exe" "sudo mono user2.exe"

Each user has a kill.sh in their directory, which is being called by user1.exe/user2.exe to kill the process.

The script itself is

ps aux | grep 'mono user1.exe' | awk '{print $1}' | xargs kill

which in theory should pull *only* the PID of "mono user1.exe" and kill only that. The problem: It kills any and every single instance of mono that is running on my system, every userx.exe thats open. I am confused, as a simple "ps aux | grep 'mono user1.exe'" does only return the mono user1.exe process and not the others. "ps aux | grep 'mono'" returns them all though. how I can modify that script so that it only kills the specific process? Would "pkill -9 -f 'mono MCuser1.exe'" work as well - or would it too kill every instance of mono? I cant do a lot more of trial and error, its not good I am killing those instances accidently...

View 14 Replies View Related

Programming :: Creating Multiple Processes Using Fork

Oct 23, 2010

As an assignment i was doing a program to create two process using fork and pass messages between them using message queue.Did it worked well until my friend tried to copy it using scp.suddenly all hell broke loose as processes without ran syncronisation ie. in tech terms the process just wont wait wen a message queue is empty.it keeps on executing randomly.but after a reboot .. everything worked fine. until again i tried to do scp on my system on purpose. and again the program just went mad.

View 3 Replies View Related

Programming :: Process P4 To Terminates Processes P1, P2, P3 If They Are Running?

Aug 18, 2009

I have p1,p2,p3,p4 some processes created by me in C. p1, p2, p3 are started individually from several consoles. And I want process p4 to terminates processes p1, p2, p3 if they are running. Which is the easiest way to accomplish that? put all processes in the same process group and send from p4 a kill signal to the group. But I couldn't do that because I cannot call successfully setpgid(getpid(), 15000) from p1-p4. It's there some way to put them in the same group? the processes don't have a child-parent relationship, they are launched manually from consoles.

View 1 Replies View Related

Programming :: Synchronization Of Two Processes With Share Memory?

Feb 27, 2011

I have two processes that share a piece of memory, and i want to use the shared memory to send data from one process to the other. it's like a simple consumer-producer problem. when the producer fills the shared memory, it waits until the consumer can consume some data in the memory; the consumer needs to wait if there is no data in the memory. The thing gets complicated when both threads are allowed to sleep and wait for the other to wake it up.

i wanted to use condition variable of pthread for synchronization, but it doesn't work in multiple processes. i tried semaphore, but it's quite complicated and i still cannot make it right. I believe it's a common problem and someone should have written similar code before, or maybe the code is even wrapped in a library, but when I search for it on Internet, I only found information about how to share memory between processes. Does anyone know where I can find this kind of code or library?

View 2 Replies View Related

Programming :: Python: List Running Audio Processes?

Jul 19, 2010

I am trying to get a list of running processes using audio (using gstreamer), just like in gnome-volume-control, under applications, but have so far been unsuccessful in finding anything in either the gtk or gstreamer library, anyone out there who can point me in the right direction?

View 1 Replies View Related

Programming :: Simulate Key Strokes Events In Other Processes In System?

Feb 3, 2011

I have a program that receive user input.
I want to run this program automatically without user interaction, and in order to do that I need to simulate key events.
How can I do such a thing?

The program I am running is partly java and partly shell.

The shell part is easily done by using:
./prog.sh <parameters (Parameters being a file containing parameters)
But the java doesn't work similarly.

View 7 Replies View Related

Programming :: Find Number Of Child Processes (C / POSIX)?

May 26, 2010

I'm in the process of writing a program that is a server- it will accept connections and stuff, and spawn a child process for each. However, i've run into a small problem. I do NOT want to bother with keeping track of the processes unless i need to. So, i set SA_NOCLDWAIT (#ifdef) on a SIG_IGN to the SIGCHLD handler through sigaction interface. The standard says that it the kernel will then keep track of reaping zombie processes for me (a HUGE plus). However, upon receiving a SIGINT signal, i want to stop the server from accepting new connections (done), and then wait for there to be no new connections. I was thinking of just putting a loop like so:

Code:

while((wait(NULL) != (pid_t)-1) && errno != ECHILD);

However, I'm not *sure* that this will work, especially with SIGCHLD still ignored. So how can i tell if there are still child processes? I can't find any call like int getnumchld(pid_t proc); (i wish). Plus it would be inefficient to spin on that function anyway. OTOH, i would rather *NOT* have to do the same thing in a loop with a system("ps |...>file"); read(file); etc. either. Is there a way i can portably implement this feature (I was hoping i could run it on linux and the major BSDs, at least).

TO SUM IT UP:

How can i tell if a process has no child processes if i've SIG_IGN'd SA_NOCLDWAIT'd the SIGCHLD? Is there a _reasonably_ portable way to do so? I *don't* want to manually wait for EVERY process. Maybe only those still active at the time of SIGTERM, but that requires keeping track of the number of connections and whether those have terminated...

EDIT: Does anyone know if the above code *would* work, even with SIGCHLD ignored and the kernel cleaning up zombies *for* me? I checked the manpage and it doesn't say much.

EDIT1: Note that all of the processes are in the same process group and session. SO i can find them through this as well. Perhaps even setting the uid/gid and finding all processes run by that group?

EDIT2: i have an idea if the above isn't feasible. If there is no "elegant" way to do it, i could reduce the complexity by sending a SIGUSR1 to the whole process group. Each process would then set a flag telling it to send a SIGUSR1 in reply and send a SIGUSR2 when it is done executing. Then i could keep a count of signals. Maybe that would be *easier*. Or perhaps a count of all child processes and just a termination signal to decrement the counter.

View 2 Replies View Related

Programming :: Show The Top Processes Eating RAM In Human Readable?

Aug 14, 2010

I want to find out which process is eating RAM, I use this command:

Code:

ps -eo size,pid,user,command | sort -k1 -rn | head -10

but it displays with no human readable:

Code:

283364 4644 quanta /usr/lib/mozilla-firefox/firefox --sm-config-prefix /firefox-C3JYUC/ --sm-client-id 1014cd7d2d4000128169799000000044950019 --screen 0
230372 3635 mysql /usr/sbin/mysqld --defaults-file=/etc/mysql/my.cnf --basedir=/usr --datadir=/var/lib/mysql --pid-file=/var

[code]....

use 'awk' to convert 'size' column to human readable? I also read this thread but I get stuck in printing from $4 to NR.

View 8 Replies View Related

Programming :: Perl - Multiple Child Processes In Parallel?

Sep 3, 2010

I'm looking for a way in Perl to be able to take a list of servers, ssh multiple commands to it and store the results. If I do this process serially, sometimes one server will hang the whole script and if it doesn't, it still takes hours to complete.

I'm thinking what I need to do is make a parent loop that calls out a separate process that passes the server name to the child sub process and then executes all the commands I have defined in its own process. If one server 'hangs', at least that won't stop the script from doing all the other servers in the list.

I'm guessing using the fork() command would serve me best, however, all the online descriptions I have found have been vague at best.

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved