Question about system command in C


 
Thread Tools Search this Thread
Top Forums Programming Question about system command in C
# 1  
Old 03-17-2011
Question about system command in C

The man system says

During execution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT will be ignored.

What does this mean?
And if i am making a function that does what system does how do i write this signal stuff?
# 2  
Old 03-17-2011
Quote:
Originally Posted by omega666
The man system says

During execution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT will be ignored.

What does this mean?
It means that SIGCHLD signals won't be handled during the time system() is still being processed.
Quote:
And if i am making a function that does what system does how do i write this signal stuff?
You do that with sigprocmask, which is used to view or modify the set of signals the process is currently blocking or whatever. Change the signals at the beginning and then, right before you return, change them back. See man sigprocmask.
# 3  
Old 03-17-2011
I'm still not understanding how to ignore SIGINT and SIGQUIT in the parent and not the child.
If i press ctrl-c while the child process is still going on, its supposed to end the child process, and create a zombie process (parent)?

Last edited by omega666; 03-17-2011 at 06:38 PM..
# 4  
Old 03-17-2011
Quote:
Originally Posted by omega666
I'm still not understanding how to ignore SIGINT and SIGQUIT in the parent and not the child.
Set the parent to ignore them, fork(), then change it back in the child.
Quote:
If i press ctrl-c while the child process is still going on, its supposed to end the child process, and create a zombie process (parent)?
I'm not completely sure. what actualy ends up happening?

Code:
int system_new(const char *comm) {
    int fd[2], status, pid; 
    if (pipe(fd) < 0) { 
        perror("pipe failed"); 
        return ((int) NULL);
    }
    if ((pid = fork()) == 0) { 
        close(fd[0]); close(fd[1]);
        execl("/bin/sh", "/bin/sh", "-c", comm, NULL); 
        perror("couldn't execl"); exit(127); 
    }
    else if (pid > 0) { 
        close(fd[0]); close(fd[1]); 
        wait(&status); 
    }
    else { 
        close(fd[0]); close(fd[1]);
        perror("fork failed"); exit(-1); 
    }
    return WEXITSTATUS(status); 
}

You're not actually using the pipe here, so you can cut all the bits that create and close the pipe...
# 5  
Old 03-17-2011
To block SIGCHLD in the parent do i need
sigset_t new;
sigemptyset (&new);
sigaddset(&new, SIGCHLD);
sigprocmask(SIG_BLOCK, &new, NULL);
?

Last edited by omega666; 03-17-2011 at 06:38 PM..
# 6  
Old 03-17-2011
That'd work, yes.

I'd keep a copy of the old signals just to make it easy to undo.
Code:
sigset_t new, old;
sigemptyset (&new);
sigaddset(&new, SIGCHLD);
sigprocmask(SIG_BLOCK, &new, &old);

...

// in child, undo by setting to the old mask
sigprocmask(SIG_SETMASK&old, NULL);

# 7  
Old 03-17-2011
so like
this will block SIGCHLD in parent, so if one were to press ctrl-c when child were running, what would happen?

Last edited by omega666; 03-17-2011 at 06:38 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Question on Veritas file system..

Hi, I am on Solaris 10 server which is running Veritas. It's E420 server with two drives. I don't know much about Veritas. The other guy who works on this, on vacation this week. :-) Any way, looks like I have hard drive issue on the server. When I do iostat -E. I see this. sd0... (4 Replies)
Discussion started by: samnyc
4 Replies

2. UNIX for Dummies Questions & Answers

question about unix file system

Hi, The file system unix use a multilevel indexes access to disk, 12 direct blocks, 1 single indirect block, 1 double indirect block, 1 triple indirect block: Assuming a: block = 512 bytes, pointer = 4 byte, and there is a file of 200 blocks, how many disk access is needed to read the block... (1 Reply)
Discussion started by: blob84
1 Replies

3. UNIX for Dummies Questions & Answers

Unix directory system calls question

I'm currently studying for my exam, and is practicing with sample exam questions. However there is a question asking "Name THREE UNIX Directory system calls" and the answer given is "opendir, closedir and readdir", however the next question ask "Why is a write directory system call not included... (1 Reply)
Discussion started by: Izzy123
1 Replies

4. Shell Programming and Scripting

System Command dies even when command gets executed successfully

Hi I have created a perl script & running it using Linux machine. I want my script to die when system command is unsuccessful but script is dying even when system command gets executed successfully. :wall: I am using the command below :- system($cmd) || die "FAILED $!"; print "Hello"; ... (2 Replies)
Discussion started by: Priyanka Gupta
2 Replies

5. Programming

question about system and popen in C

in man system it talks about SIGCHLD will be blocked, and SIGINT and SIGQUIT will be ignored. Does this signal stuff also happen in popen command? (even though man popen says nothing about signals) also if I am not using wait(&status) and I am using waitpid(pid, NULL, 0) how would... (1 Reply)
Discussion started by: omega666
1 Replies

6. Solaris

File system - question?

Hello, I have few questions about file system in Unix and Linux. 1. What's the difference between Unix and Linux in their file system? Are they the same? 2. Is in Unix directory for administrator "/root" - like in Linux - Ubuntu or not? 3.Where is the users directory in Unix? Is it... (2 Replies)
Discussion started by: niki22
2 Replies

7. Programming

Question about the system() function in C

Hello all ! Could someone throw some light on whether there's a limit to the number of characters contained in the command string that is passed to the system() call in C. Is it OS dependent? If yes, what are the limits for each? Thanks. (4 Replies)
Discussion started by: vsanjit
4 Replies

8. UNIX for Dummies Questions & Answers

solaris File system question ( UFS )

Hello all, I'm ufs file system, how can u use the same disk in another machine with the data in tact? to make it clear, I've an ufs FS in a mount point /file1 ( 8GB). now they decide to reintall the OS. After the reinstall, how can i get the same data as it is? will mounting the disk as /file1... (3 Replies)
Discussion started by: i2admin
3 Replies

9. IP Networking

I have some question on unix system

Dear all, If I login to a Unix system (general user account), will the unix system generate a history file? If positve, will it stored the IP adress also? Thanks and Regards Penny Li ;) (2 Replies)
Discussion started by: PennyLi
2 Replies
Login or Register to Ask a Question