I feel so stupid, but I can't create a makefile. I ave this C program titled Beginner.c. All of the makefile tutorials I have seen on the net require you to have object files and all of these headers. Frankly, it's way over my head. Could anyone explain it to me? Here's my source code if you need it to figure out how to make a makefile. It seems silly tomake a makefile for just 1 c file, but we have to do it for a class. thanks for the help. BTW, this code simulates a parallel sort.
Code:#include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <string.h> #include <sys/types.h> #include <stdlib.h> #include <string.h> void childProcess(int currentProcess); void parentProcess(int numProcesses); int atoi( const char *str ); int numLines; //number of lines in each file int numProcesses; //number of processes entered by the user int numLinesPerFile; pid_t pid; //process ID so we know whether it's a child or parent processs int status; char fileNames[] = "abcdefghijklmnopqrstuvwxyz"; //this program can handle up to 26 processes int main(int argc, char *argv[]) { //get the information from the command line numLines = atoi(argv[2]); numProcesses = atoi(argv[3]); numLinesPerFile = numLines / numProcesses; //check to make sure the user entered the correct number of arguments. If they didn't, //print an error message and quit if(argc != 4) { printf("\nERROR! Wrong number of arguments.\n\n"); return 0; } //print out the parameters the user entered for verification //this prints out the filename entered fprintf(stdout,"\n"); fprintf(stdout, argv[1]); printf("\nNumber of lines: %d\n", numLines); printf("Number of processes: %d\n", numProcesses); printf("\n\nNumber of lines per file: %d\n", numLinesPerFile); //arbitrary buffer size of 200 to be sure that the string will fit //this will split the file up according to the number of processes char buff[200]; sprintf(buff, "split -l %d %s ", numLinesPerFile, argv[1]); system(buff); int extraLines = numLines - numLinesPerFile*numProcesses; //printf("\n\nThe number of extra lines is: %d", extraLines); if(extraLines != 0) { char buff[200]; sprintf(buff, "sort -o xa%c -m xa%c xa%c", fileNames[numProcesses-1], fileNames[numProcesses-1], fileNames[numProcesses] ); system(buff); sprintf(buff, "rm xa%c", fileNames[numProcesses]); system(buff); } //this portion of the code will use the fork() to create new processes int i; for(i = 0; i < numProcesses; i++) { //keep up with the current process so we know which file to sort int currentProcess = i; //fork the current process pid = fork(); if(pid == 0) //i am a child! { childProcess(currentProcess); } else //i am your parent! { //pass the number of processes so the parent knows how many files to merge parentProcess(numProcesses); } } return 0; }//end of main function void childProcess(int currentProcess) { //this portion will sort the file of the child we are on char buff[200]; sprintf(buff, "sort xa%c -n -o xa%c", fileNames[currentProcess], fileNames[currentProcess]); system(buff); return; }//end child function void parentProcess(int numProcesses) { printf("\nI AM YOUR FATHER!\n"); int l; //for(l = 0; l < numProcesses; l++) //{ //wait for all of the children to catch up wait(&status); //} int j; //arbitrary buffer sizeto hold the entire merge char buffer[2000]; for(j = 0; j < numProcesses; j++) { //if we are on the first item just take the name xaa if(j == 0) { sprintf(buffer, "xa%c ", fileNames[j]); } //if we aren't on the first file we have to do some concatenation with //the new file name and the old ones else { char newBuffer[200]; sprintf(newBuffer, "xa%c ", fileNames[j]); strcat(buffer, newBuffer); } } //this part actually merges the sorted children's files char string[20000]; sprintf(string, "sort -o outfile -m -n %s", buffer); system(string); //remove all of the intermediate files //sprintf(string, "rm %s", buffer); //system(string); return; }//end parent function



LinkBack URL
About LinkBacks



