Doing my own shell, how to properly execute processes in background/foreground?

This is a discussion on Doing my own shell, how to properly execute processes in background/foreground? within the C Programming forums, part of the General Programming Boards category; Originally Posted by brewbuck There are plenty of things you can do in C which seem to work but are ...

  1. #31
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by brewbuck View Post
    There are plenty of things you can do in C which seem to work but are completely wrong.
    Yep. I might have been being tongue in cheek there, I don't remember

    The point is, Nazgulled, your prof will know the standard and doc you for this. At least s/he should.

    Look:
    Code:
    #include <stdio.h>
    #include <string.h>
    
     int main () {
    	char X[2];
    	strcpy(X,"hello world");
    	printf("%s",X);
    	return 0;
    }
    Works for me! I guess that is correct then!
    Last edited by MK27; 05-27-2009 at 11:39 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  2. #32
    Registered User
    Join Date
    Mar 2006
    Posts
    158
    Maybe it's the irrelevant for the type of exercise?

    This class is not about C, is not about learning to code in C and do it right, is about operative systems. We just happen to use C... The idea in this class is to understand how OS's work and to play with system calls. As for this specific exercise, is to understand signals, what they are, what they mean, what they do, etc...

    I'm not really concerned about it either, it's probably the first and last time I'll ever code stuff like this and I did learn what I was supposed to from this exercise.

  3. #33
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,160
    Quote Originally Posted by Nazgulled View Post
    Maybe it's the irrelevant for the type of exercise?

    This class is not about C, is not about learning to code in C and do it right, is about operative systems. We just happen to use C...
    This is a problem of asynchronous access and concurrency, not a C-specific problem. It is at the HEART of operating systems theory.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #34
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Fair enough -- I'll just let you know why I'm warning you. If you are writing "production grade" software, ie, something that is going to be compiled on a whole bunch of different computers by other people, little bits of undefined behaviour that you were unaware of will suddenly start to show up.

    This happened to me last year, when I started testing a program I wrote for distribution on various linux installs. I only had three, two 64-bit and one 32-bit, but using three different versions of gcc and the GNU C library. Some of the bugs passed right thru both 64-bit systems and showed up on the 32-bit platform. Presumably this did catch them all, because it then got tested by a group of people at debian and they didn't find any problems. However, I was *terrified* for a little while that this beast I had spent months preparing was a piece of junk riddled with the products of my ignorance regarding UNDEFINED BEHAVIOR.

    In the context of a learning exercise I guess it does not matter, but you should not make it a habit of doing things *the wrong way* once you know that that is the case -- otherwise, all you learned was how to do something incorrectly.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #35
    Registered User
    Join Date
    Mar 2006
    Posts
    158
    Like I said, what I had to learn from this exercise, I did. I also learned, from your help, that I shouldn't do that.

    For this exercise, that's irrelevant and I'm not going to waste any more time with that. I've already moved on to the next one (as you can see with a new topic I created lol). If I happen to make a more serious program in C where I need to handle signals, I'll know that I shouldn't do stuff like that, for now, that doesn't really matter.

    By the way, thanks for all your help
    Last edited by Nazgulled; 05-27-2009 at 12:34 PM.

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Develop. Shell , Backgrounds processes
    By Barassa in forum C Programming
    Replies: 0
    Last Post: 10-22-2008, 02:42 PM
  2. binary tree of processes
    By gregulator in forum C Programming
    Replies: 1
    Last Post: 02-27-2005, 11:59 PM
  3. Program to execute shell commands.
    By LiquidLithium in forum C++ Programming
    Replies: 6
    Last Post: 09-01-2004, 12:22 PM
  4. Shell execute... but piping
    By nickname_changed in forum C++ Programming
    Replies: 2
    Last Post: 05-21-2003, 07:39 AM
  5. Problems with Shell Execute
    By golfinguy4 in forum Windows Programming
    Replies: 3
    Last Post: 12-03-2002, 11:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21