LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 10-01-2002, 09:05 AM   #1
AbhiShek
LQ Newbie
 
Registered: Oct 2002
Posts: 9

Rep: Reputation: 0
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
 
Old 10-01-2002, 10:37 AM   #2
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 55
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.
 
Old 10-01-2002, 10:54 AM   #3
AbhiShek
LQ Newbie
 
Registered: Oct 2002
Posts: 9

Original Poster
Rep: Reputation: 0
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
 
Old 10-01-2002, 11:19 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
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");
 
Old 10-01-2002, 11:45 AM   #5
AbhiShek
LQ Newbie
 
Registered: Oct 2002
Posts: 9

Original Poster
Rep: Reputation: 0
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!!
 
Old 10-01-2002, 02:42 PM   #6
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
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"?)
 
Old 10-01-2002, 02:56 PM   #7
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Essential System Administration" or "UNIX System Administration Handbook"? TGWDNGHN Linux - Newbie 3 07-03-2005 08:27 PM
where is command "cd" located? or is it a command/ system call? feetyouwell Linux - Software 5 10-01-2004 08:01 PM
"User" & "System" CPU load difference JJX Linux - General 3 06-06-2004 01:42 AM
"X-MS" cant open because "x-Multimedia System" cant access files at "smb&qu ponchy5 Linux - Networking 0 03-29-2004 11:18 PM
RH "null" beta system freezes right after printing "INIT" markus1982 Linux - Hardware 0 09-09-2002 03:31 PM


All times are GMT -5. The time now is 03:38 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration