Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * cs537 Project 1 - Shell
- *
- * Written by Stefan Strandberg (stefan@cs.wisc.edu)
- * $Id: job.c,v 1.5 2004/09/23 21:06:15 stefan Exp $
- *
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "job.h"
- #include "shell.h"
- ///////////////////
- //
- // create_job()
- //
- // * creates a job, returns it
- //
- //////////////////
- job_t *create_job(int jid, int pid, char* command, int argc, char* args[],
- int background, job_t *job) {
- job->jid = jid;
- job->pid = pid;
- job->command = malloc(MAX_INPUT_SIZE);
- if(job->command == NULL) {
- fprintf(stderr, "Unable to malloc() command in create_job()!!\n");
- exit(1);
- }
- strcpy(job->command, command);
- job->argc = argc;
- job->background = background;
- int c;
- for(c = 0; c < argc; c++) {
- job->args[c] = malloc(MAX_INPUT_SIZE);
- if(job->args[c] == NULL) {
- fprintf(stderr, "Unable to malloc() a job in create_jobs()!!\n");
- exit(1);
- }
- // job->args[c] = args[c];
- strcpy(job->args[c], args[c]);
- }
- return job;
- }
- ////////////////////
- //
- // remove_job()
- //
- // * removes a job, frees some of the memory
- //
- // *FIXME: fix memory leak!!
- //
- ///////////////////
- void remove_job(job_t *job) {
- free(job->command);
- // this free() code gives Segfaults and I don't care anymore, so it can go!
- // int c = 0;
- // //for(c = 0; c < job->argc ; c++) {
- // while (job->args[c] != NULL) {
- // printf("freeing job %d args at %d\n", job->jid, c);
- // free(job->args[c]);
- // }
- free(job);
- }
- ///////////////////
- //
- // print_job()
- //
- // * prints a job in the output needed by j
- //
- ///////////////////
- void print_job(job_t *job) {
- printf("%d : %s", job->jid, job->command);
- int c;
- for(c = 1; c < job->argc; c++)
- printf(" %s", job->args[c]);
- // printf(" pid: %d", job->pid);
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement