lab5 Pipe Signals
  • Introduction
  • Signals
    • kill() system call
    • Custom signal handler
  • Knowing about pipe
    • Pipe Overview
    • System call pipe()
  • Learn to use pipe
    • Pipe Creation
    • Pipe with fork
    • Exercise 1
  • Connecting two programs with pipe
    • Implement ls | less in C
  • Shell Examples
    • Get Current Path
    • Change Directory
    • Change Environment Variables
  • Reference
Powered by GitBook
On this page

Was this helpful?

  1. Shell Examples

Get Current Path

To get the current working directory (cwd), we can use a handy function: getcwd().

#include <unistd.h>
char *getcwd(char *buf, size_t size);
/* Shell/getcwd.c */
#include <stdio.h>
#include <limits.h> // Needed by PATH_MAX
#include <unistd.h> // Needed by getcwd()
int main(int argc,char *argv[]){
    char cwd[PATH_MAX+1];
     if(getcwd(cwd,PATH_MAX+1) != NULL){
         printf("Current Working Dir: %s\n",cwd);     
     }    
    else{         
        printf("Error Occured!\n");
    }    
 return 0;
}
PreviousShell ExamplesNextChange Directory

Last updated 5 months ago

Was this helpful?