HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- open file in C
Operating System - HP-UX
1834200
Members
2818
Online
110066
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2002 07:19 AM
03-19-2002 07:19 AM
want to open a file (/pidfile) and get the information from it into a char (named pid). got access to hp-ux 10 standard cc and gcc.
could anyone please help me with this?
could anyone please help me with this?
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2002 07:32 AM
03-19-2002 07:32 AM
Solution
Hi:
Your question is very unclear but I am going to assume that this is a textfile.
#include
#define PIDFILE "/pidfile"
FILE *f = NULL;
f = fopen(PIDFILE,"r");
if (f != NULL)
{
char pid[80],*p = NULL;
pid[0] = '\0';
p = fgets(pid,sizeof(pid),f);
(void) fclose(f);
}
else (void) fprintf(stderr,"Can't open %s\n",PIDFILE);
Note: pid in this case may have a Linefeed on the end; you may need to strip it off.
Your question is very unclear but I am going to assume that this is a textfile.
#include
#define PIDFILE "/pidfile"
FILE *f = NULL;
f = fopen(PIDFILE,"r");
if (f != NULL)
{
char pid[80],*p = NULL;
pid[0] = '\0';
p = fgets(pid,sizeof(pid),f);
(void) fclose(f);
}
else (void) fprintf(stderr,"Can't open %s\n",PIDFILE);
Note: pid in this case may have a Linefeed on the end; you may need to strip it off.
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2002 07:41 AM
03-19-2002 07:41 AM
Re: open file in C
#include
#include
char *pidinfo;
main()
{
FILE *input_file;
input_file = fopen("./pidfile","r");
fscanf(input_file,"%s",&pidinfo);
printf("%s\n",&pidinfo);
exit(0);
}
As Clay said, without knowing what the "/pidfile" looks like, I'm going to assume it's a normal pidfile like syslogd's.
live free or die
harry
#include
char *pidinfo;
main()
{
FILE *input_file;
input_file = fopen("./pidfile","r");
fscanf(input_file,"%s",&pidinfo);
printf("%s\n",&pidinfo);
exit(0);
}
As Clay said, without knowing what the "/pidfile" looks like, I'm going to assume it's a normal pidfile like syslogd's.
live free or die
harry
Live Free or Die
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2002 06:47 AM
03-28-2002 06:47 AM
Re: open file in C
thanks for all the help
heres my complete solution:
#include /* needed for printf, fscanf and fopen */
#include /* needed for atol */
#include /* needed for kill */
static char *pidinfo;
main()
{
int sig=9; /* declare wich signal kill() will use */
long pid=0;
FILE *input_file;
input_file = fopen("/pidfile","r"); /* open file */
fscanf(input_file,"%s",&pidinfo); /* read file */
pid=atol(&pidinfo); /* convert char pid to long pid (needed by kill()) */
printf("killing %d\n",pid); /* some nice output for before killing */
kill(pid, sig); /* killing */
exit(0);
}
heres my complete solution:
#include
#include
#include
static char *pidinfo;
main()
{
int sig=9; /* declare wich signal kill() will use */
long pid=0;
FILE *input_file;
input_file = fopen("/pidfile","r"); /* open file */
fscanf(input_file,"%s",&pidinfo); /* read file */
pid=atol(&pidinfo); /* convert char pid to long pid (needed by kill()) */
printf("killing %d\n",pid); /* some nice output for before killing */
kill(pid, sig); /* killing */
exit(0);
}
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP