Click here to Skip to main content
15,885,876 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: MenuItems' Icons are not Displaying properly in MFC Pin
Gary Qiu25-Oct-12 5:42
Gary Qiu25-Oct-12 5:42 
QuestionChartFX Compatiability Pin
Andrew Hoole24-Oct-12 5:50
Andrew Hoole24-Oct-12 5:50 
QuestionRe: ChartFX Compatiability Pin
David Crow24-Oct-12 6:05
David Crow24-Oct-12 6:05 
AnswerRe: ChartFX Compatiability Pin
Andrew Hoole24-Oct-12 6:24
Andrew Hoole24-Oct-12 6:24 
GeneralRe: ChartFX Compatiability Pin
Andrew Hoole24-Oct-12 22:00
Andrew Hoole24-Oct-12 22:00 
AnswerRe: ChartFX Compatiability Pin
krmed24-Oct-12 7:12
krmed24-Oct-12 7:12 
AnswerRe: ChartFX Compatiability Pin
Gary Qiu25-Oct-12 5:46
Gary Qiu25-Oct-12 5:46 
Questionthe program exit after creating process in the solaris Pin
jonesliu24-Oct-12 0:51
jonesliu24-Oct-12 0:51 
Hi all:
I have run the program successfully in the Linux
but it failed in the solaris, the program will exit after creating process.
I don't known the different between the solaris and linux.

The output when running the programm:
9
10
2
3
4=3374
9
10
1=3373



The part code as following.
// unix daemon

#include <fcntl.h>
#include <sys resource.h="">
#include <stdio.h>
#include <stdlib.h>
#include <sys types.h="">
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <sys stat.h="">
#include "SPSServiceApp.h"

#define LOCKFILE "/var/run/SPSService.pid"
#define LOCKMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)

void daemonize(const char* cmd)
{
int i, fd0, fd1, fd2;
pid_t pid;
struct rlimit rl;
struct sigaction sa;

// Clear file creation mask
umask(0);

// Get maximum number of file descriptors
if (getrlimit(RLIMIT_NOFILE, &rl) < 0)
{
fprintf(stderr, "%s: can't get file limit", cmd);
exit(1);
}

if ((pid = fork()) < 0)
{
fprintf(stderr, "%s: can't fork", cmd);
exit(1);
}
else if (pid != 0) //parent
{
printf( "1=%d\n", getpid());
//printf( "1ppid=%d\n", ggetpid());
exit(0);
}
setsid();
printf( "2\n");

// Ensure future opens won't allocate controlling TTYs.
sa.sa_handler = SIG_IGN;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
if (sigaction(SIGHUP, &sa, NULL) < 0)
{
fprintf(stderr, "%s, can't ignore SIGHUP", cmd);
exit(1);
}
printf( "3\n");
if ((pid = fork()) < 0)
{
fprintf(stderr, "%s: can't fork", cmd);
exit(1);
}
else if (pid != 0) //parent
{
printf( "4=%d\n", getpid());
//printf( "4ppid=%d\n", ggetpid());
exit(0);
}
printf( "5\n");

if (rl.rlim_max == RLIM_INFINITY)
{
rl.rlim_max = 1024;
}
for (i = 0; i < rl.rlim_max; ++i )
{
close(i);
}
printf( "6\n");
fd0 = open("/dev/null", O_RDWR);
printf( "7\n");
fd1 = dup(0);
fd2 = dup(0);
if (fd0 != 0 || fd1 != 1 || fd2 != 2)
{
printf( "8\n");
exit(1);
}
}

int lockfile(int fd)
{
struct flock fl;

fl.l_type = F_WRLCK;
fl.l_start = 0;
fl.l_whence = SEEK_SET;
fl.l_len = 0;
return(fcntl(fd, F_SETLK, &fl));
}

int already_running(void)
{
int fd;
char buf[16];

fd = open(LOCKFILE, O_RDWR | O_CREAT, LOCKMODE);
if(fd < 0)
{
exit(1);
}
if (lockfile(fd) < 0)
{
if (errno == EACCES || errno == EAGAIN)
{
close(fd);
return(1);
}

exit(1);
}

ftruncate(fd, 0);
sprintf(buf, "%ld", (long)getpid());
write(fd, buf, strlen(buf) + 1);
return(0);
}

int main(int argc, char* argv[])
{
char* cmd;
struct sigaction sa;

printf("9\n");
if ((cmd = strrchr(argv[0], '/')) == NULL)
{
cmd = argv[0];
}
else
{
++cmd;
}



// Become a daemon
printf("10\n");
daemonize(cmd);

printf("11\n");
// Make sure only one copy of the daemon is running
if (already_running())
{
exit(1);
}

printf("12\n");
sa.sa_handler = SPSServiceApp::sig_term;
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, SIGHUP);
sa.sa_flags = 0;
if(sigaction(SIGTERM, &sa, NULL) < 0)
{
exit(1);
}

printf("13\n");
sa.sa_handler = SPSServiceApp::sig_hup;
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, SIGTERM);
sa.sa_flags = 0;
if(sigaction(SIGHUP, &sa, NULL) < 0)
{
exit(1);
}

wxEntry(argc, argv);
printf("14\n");

exit(0);
}
AnswerRe: the program exit after creating process in the solaris Pin
Richard MacCutchan24-Oct-12 1:06
mveRichard MacCutchan24-Oct-12 1:06 
QuestionFinding Min and Max of array Pin
Mikerush723-Oct-12 6:50
Mikerush723-Oct-12 6:50 
AnswerRe: Finding Min and Max of array Pin
jeron123-Oct-12 7:36
jeron123-Oct-12 7:36 
AnswerRe: Finding Min and Max of array Pin
Chris Losinger23-Oct-12 8:31
professionalChris Losinger23-Oct-12 8:31 
AnswerRe: Finding Min and Max of array Pin
CPallini23-Oct-12 10:47
mveCPallini23-Oct-12 10:47 
AnswerRe: Finding Min and Max of array Pin
«_Superman_»23-Oct-12 19:34
professional«_Superman_»23-Oct-12 19:34 
AnswerRe: Finding Min and Max of array Pin
Sajeesh Payolam23-Oct-12 20:10
Sajeesh Payolam23-Oct-12 20:10 
GeneralRe: Finding Min and Max of array Pin
Mikerush724-Oct-12 3:28
Mikerush724-Oct-12 3:28 
QuestionHow to delete Registry Key with Maximum rights Pin
platso_58823-Oct-12 2:40
platso_58823-Oct-12 2:40 
AnswerRe: How to delete Registry Key with Maximum rights Pin
Jochen Arndt23-Oct-12 3:02
professionalJochen Arndt23-Oct-12 3:02 
GeneralRe: How to delete Registry Key with Maximum rights Pin
platso_58824-Oct-12 5:17
platso_58824-Oct-12 5:17 
GeneralRe: How to delete Registry Key with Maximum rights Pin
Jochen Arndt24-Oct-12 5:45
professionalJochen Arndt24-Oct-12 5:45 
GeneralRe: How to delete Registry Key with Maximum rights Pin
platso_58824-Oct-12 20:27
platso_58824-Oct-12 20:27 
GeneralRe: How to delete Registry Key with Maximum rights Pin
Jochen Arndt24-Oct-12 21:15
professionalJochen Arndt24-Oct-12 21:15 
Questionmessage CBN_SELENDOK not sent when using mouse Pin
NoviceEx23-Oct-12 2:07
NoviceEx23-Oct-12 2:07 
AnswerRe: message CBN_SELENDOK not sent when using mouse Pin
Jochen Arndt23-Oct-12 2:51
professionalJochen Arndt23-Oct-12 2:51 
GeneralRe: message CBN_SELENDOK not sent when using mouse Pin
NoviceEx23-Oct-12 3:05
NoviceEx23-Oct-12 3:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.