LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Using the "system( )" system call causes exit sometimes (https://www.linuxquestions.org/questions/linux-software-2/using-the-system-system-call-causes-exit-sometimes-31592/)

AbhiShek 10-01-2002 09:05 AM

Using the "system( )" system call causes exit sometimes
 
I am having a problem using system(..) function. I am trying to do a ifconfig using the
system(..) function however, the program exits in the call to the system(..) function.

I've tried this before in a different part of code and it did work. It somehow mysteriously doesn't seem to work anymore. I can still do a ifconfig call from the command line instead of doing from my code and that works just fine.

Any help is greatly appreciated.

Thanks for your time,

Abhi

neo77777 10-01-2002 10:37 AM

It is a very vague question, I have a car, and the thing is I can't started - possibilities:
1. You don't have an ignition key
2. You don't have an engine.
3. You don't have .... you got it
So please, we need more details, like for instance what language do you use? C, perl, bash scripting, etc.

AbhiShek 10-01-2002 10:54 AM

Sorry about that Neo. I'm a newbie posting a message for the first time. I'm sure you've figured that out by now:)

I am programming in C using Redhat 7.3. kernel 2.4.7-10. I have found something more upon debugging it further. It seems like the system(..) function call forks a process and executes the command within that process. In my case the command i am trying to execute is ifconfig. Upon executing the command this newly created process by the system (..) exits. The problem seems to be the way the signal handler is installed in my parent process i.e. the process that executes the system function call. I am pretty certain that the signal handler is causing the process to exit. I am in the process of finding that out for certain. Does that make more sense ? However, the question still remain why the same system("ipconfig sl0 172.16.17.xxx pointopoint 172.16.17.xxx") worked before. I am trying to set up a slip device using the ifconfig call.

Thanks for your time. Appreciate it. Hopefully, the new information makes more sense.

Abhi

Hko 10-01-2002 11:19 AM

Guessing a bit...but maybe you started it as root and it worked. Now you start it as a regular user, and it doesn't work? The reason could be then that ifconfig is not in your $PATH. If this is the case, use the path from / i.e. system("/sbin/ifconfig");

AbhiShek 10-01-2002 11:45 AM

I've been running the program as root from the beginning and the ifconfig is in my $PATH. Either way i.e. /sbin/ifconfig or /ifconfig causes the exit to occur.

I just uninstalled my signal handler for SIGCHLD and it now WORKS. Still need to investigate how it worked before. The answer i guess may lie in my signal handler. I'll post a message once i get the whole thing figured out again. However, it suprises me that a call to the system("ifconfig...") generates a SIGCHLD. The process that makes the system call has no idea that a child was spawned and i would have assumed that it would not get the SIGCHLD. Another intersting thing is that if you don't catch the SIGCHLD, there is no zombie process created which i believe means that the system function did wait and collect the exit status of the child.

I debugged this using strace on the process. For future reference, is there a better way to trace such system calls.


Thanks again!!

Hko 10-01-2002 02:42 PM

Quote:

The process that makes the system call has no idea that a child was spawned [...]
...but the kernel does, I think. (or is in "init"?)

neo77777 10-01-2002 02:56 PM

Look if there are any zombified processes running around, he-he.
ps -fuax |grep Z


All times are GMT -5. The time now is 12:30 AM.