User Tools

Site Tools


user:kkrauss1:portfolio:mod_data

Project: Modified oece prog

A project for C/C++, Data Structures, and System Programming by Karl Krauss for fall 2011.

This program only took about an hour.

Objectives

The purpose of this project was to modify a program to work with processes using c.

Attributes

Data Structures

  • Pointers
  • sorts

Systems programming

  • processes
  • command line arg
  • timers
  • io redirection

Code

This is the header file:

 *
 */
#include<sys/types.h>
#include<unistd.h>
//#include<iostream>  this is for c++ output and is not needed
//#include<cstdlib> this is for c++ output and is not needed 
#include<sys/wait.h>
#include<stdio.h> // need this for c IO
#include<stdlib.h> // needed for c
 
#define DINGLEHOPPER    fork()
#define SNARFBLAT       wait(status)
 
int main(int argc, char **argv)
{
    int i = 0, *status;
    pid_t me; 
 
    me = getpid();
 
    if (argc < 2)
    {   
        //std :: cout << "Please provide a list of positive unique whole numbers\n"; this is c++ output so removed
		printf("Please provide a list of positive unique whole numbers\n"); //c output added
        exit(1);
    }   
 
    for(i=1; i<argc; i++)
    {   
        DINGLEHOPPER;
 
        if(getpid() != me)
        {
            sleep(atoi(argv[i]));
            //std :: cout << atoi(argv[i]) << " "; c++ output so removed
			printf("%d ", atoi(argv[i])); // c output added
            exit(0);
        }
    }
 
    for(i=1; i<argc; i++)
        SNARFBLAT;
 
    //std :: cout << std :: endl; c++ output so removed
	printf("\n");
 
    return(0);
}
user/kkrauss1/portfolio/mod_data.txt · Last modified: 2011/12/12 17:05 by kkrauss1