Created
November 8, 2012 21:47
-
-
Save figaw/4041899 to your computer and use it in GitHub Desktop.
university dOpSys WEEK1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***** testmini.c *****/ | |
#include <stdio.h> | |
int main(int argc, char* argv[]){ | |
printf("hello, world %s\n", argv[1]); | |
} | |
/***** forback.c *****/ | |
/* | |
Opgave 1 | |
forback.c | |
*/ | |
#include <stdio.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
#include <sys/wait.h> | |
#include <stdlib.h> | |
#include "forback.h" | |
/* start the program specified by filename with the arguments in argv | |
in a new process and wait for termination */ | |
int foregroundcmd(char *filename, char *argv[]) | |
{ | |
// alloker variabel til at holde et processID | |
pid_t processID; | |
printf("good so far 1 \n"); | |
// fork skaber en childprocess og returnerer dets pid | |
processID = fork(); | |
printf("good so far 2 \n"); | |
// kører en fil med nogen argumenter | |
execvp(filename, argv); | |
printf("good so far 3 \n"); | |
// venter på at processen med argumentets | |
// process id kører færdig | |
// waitpid(processID); | |
printf("good so far 4 \n"); | |
return EXIT_SUCCESS; | |
} | |
/* start the program specified by filename with the arguments in argv | |
in a new process */ | |
int backgroundcmd(char *filename, char *argv[]) | |
{ | |
return 0; | |
} | |
int main(int argc, char* argv[]){ | |
// so . try launching | |
*argv++; | |
foregroundcmd(argv[0], argv); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment