Results 1 to 6 of 6
Hi all,
I have created a library file suppose lib.o
I want to create a function in this library, so that any program compiled with this library will print the ...
- 06-06-2007 #1Just Joined!
- Join Date
- Jun 2007
- Posts
- 2
How to get a process's executable name during execution
Hi all,
I have created a library file suppose lib.o
I want to create a function in this library, so that any program compiled with this library will print the name of the executable.
e.g.
myprog.c
int main(){
function_from_liberary();
}
and liberary file
lib.c contains
void function_from_liberary() {
printf ("\nExecutable name is %s",what_to_write_here);
}
i compile using
gcc -c lib.c
gcc -g -o myprog myprog.c lib.o
Please help
Thanx and regards
- 06-06-2007 #2Just Joined!
- Join Date
- Jan 2006
- Location
- India
- Posts
- 52
void function_from_liberary() {
printf ("\nExecutable name is %s",argv[0]);
}
- 06-06-2007 #3Linux User
- Join Date
- Oct 2004
- Location
- /dev/random
- Posts
- 404
The Unforgiven
Registered Linux User #358564
- 06-06-2007 #4Linux User
- Join Date
- Oct 2004
- Location
- /dev/random
- Posts
- 404
- 06-07-2007 #5Just Joined!
- Join Date
- Jun 2007
- Posts
- 2
error: dereferencing pointer to incomplete type
Hi all,
I have changed my program as follows. but it gives error:
line 7: error: dereferencing pointer to incomplete type
1. #include<stdio.h>
2. #include<sys/stat.h>
3. #include<stdlib.h>
4. void execname() {
5. struct task_struct *my;
6. my = find_task_by_id(getpid());
7. printf("%s",my->comm); error: dereferencing pointer to incomplete type
8.
9. }
10. int main()
11. {
12. execname();
13. }
what's wrong with it
- 06-17-2008 #6Just Joined!
- Join Date
- Jun 2008
- Posts
- 3
__progname
__progname (and __progname_full) are possible ways to access the executable's name at runtime without having to store off values from argv**. I don't believe it's entirely standard, but it's available and is what glibc's assert uses.
extern const char *__progname;
void print_progname() {
printf("Name: %s\n", __progname);
}


Reply With Quote
