08-Process_Control

08-Process_Control - CSC 4304 - Systems Programming Fall...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CSC 4304 - Systems Programming Fall 2010 Tevfik Ko ! ar Louisiana State University September 16th, 2010 Lecture - VIII Process Control Environment Variables $ env HOSTNAME=classes TERM=xterm-color USER=cs4304_kos HOSTTYPE=x86_64 PATH=/usr/local/bin:/usr/bin:/opt/gnome/bin:/usr/lib/ mit/sbin:./ CPU=x86_64 PWD=/classes/cs4304/cs4304_kos LANG=en_US.UTF-8 SHELL=/bin/bash HOME=/classes/cs4304/cs4304_kos MACHTYPE=x86_64-suse-linux LOGNAME=cs4304_kos ... 2 Updating the Environment $ course=csc4304 $ export course $ env | grep course course=csc4304 or $export course="systems programming" $ env | grep course course=systems programming 3 How is Environment Implemented? 4 Example 1 #include <stdio.h> #include <malloc.h> extern char **environ; main() { char ** ptr; for (ptr=environ; *ptr != 0; ptr++) printf("%s\n", *ptr); } 5 Example 2 #include <stdio.h> #include <malloc.h> main(int argc, char *argv[], char *env[]) { char ** ptr; for (ptr=env; *ptr != 0; ptr++) printf("%s\n", *ptr); } 6
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
system function • used to execute command strings • e.g. system(“date > file”); • implemented using fork(), exec(), and waitpid() 7 int system(const char *command); Example 3 #include <stdio.h> #include <unistd.h> extern char **environ; main() { char *newenv[5]; printf("The current environment is. .\n"); system("env"); printf("***** Now Replacing Environment. ..\n"); getchar(); newenv[0] = "HOME=/on/the/range"; newenv[1] = "LOGNAME=nobody"; newenv[2] = "PATH=.:/bin:/usr/bin";
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/23/2011 for the course CSC 4303 taught by Professor Staff during the Fall '10 term at LSU.

Page1 / 4

08-Process_Control - CSC 4304 - Systems Programming Fall...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online