linux find the command invoked
Posted
by
Subbu
on Stack Overflow
See other posts from Stack Overflow
or by Subbu
Published on 2013-10-19T03:26:06Z
Indexed on
2013/10/19
3:54 UTC
Read the original article
Hit count: 108
I am writing a C program which determines the number of bytes read from the standard input . I found out there are ways to give input to the program
- piped input
- redirection
- entering into command line while the program is waiting for input
How to find the exact command by which the program was executed from the shell . I tried using command-line arguments but failed .
#include <stdio.h>
int main(int argc,char *argv[])
{
char buffer[100];
int n;
for(n=1;n<argc;n++)
printf("argument: %s\t",argv[n]);
printf("\n");
if(argc==1)
printf("waiting for input :");
else if (argc==3)
printf("Not waiting for input . Got the source from command itself .");
n = read(0,buffer,100);
if(n==-1)
printf("\nError occured in reading");
printf("\nReading successfully done\n");
return 0;
}
Also ,
© Stack Overflow or respective owner