我想用 sudo 启动一个程序,我用过这个命令
sudo './ConnectionManager'
在一个:
Distributor ID: ScientificSL
Description: Scientific Linux SL release 5.5 (Boron)
Release: 5.5
Codename: Boron
(Like Centos5.5)
它有效,但它不起作用
Distributor ID: Scientific
Description: Scientific Linux release 6.4 (Carbon)
Release: 6.4
Codename: Carbon
在最后一种情况下,我立即收到以下消息:[1]+ Stopped sudo './ConnectionManager'
我检查了代码,问题是int setpgrp(void)
ConnectionManager 中的指令。
ConnectionManager 是一个用 C 语言编写的程序,它派生一个进程以等待 tcp/ip 连接。
有人可以帮助我吗?
遵循示例代码
#include <stdio.h>
#include <ncurses.h>
...
int main()
{
if (chdir("/opt/informix/server") == -1)
{
printf("Errore nella directory /opt/informix/server\n");
getch();
exit(1);
};
signal(SIGINT, onexit);
signal(SIGUSR1, RefreshMainWindow);
signal(SIGPIPE, SIG_IGN);
signal(SIGCLD, SIG_IGN);
setpgrp();
ParentPid = getpid();
/***/
if (LockFile(_true) != _ok)
{
exit(1);
}
if (CreateDestroyShm(_true) != _ok)
{
exit(1);
}
...
if (LockFile(_false, &sdebug) != _ok)
{
exit(1);
}
/***/
init_curses();
menubar = subwin(stdscr, 1, MAXCOLS, 0, 0);
main_win = subwin(stdscr, MAXROWS-1, MAXCOLS, 1, 0);
cbreak(); /* immediately acquire each keystroke */
PrintTestata();
draw_menubar(menubar);
/***/
switch (fork())
{
case 0:
signal(SIGUSR1, SIG_IGN);
break;
default:
KeyboardHandler();
}
void init_curses()
{
putenv("TERM=xterm");
initscr();
wresize(stdscr, MAXROWS, MAXCOLS);
start_color();
init_pair(1,COLOR_WHITE,COLOR_RED);
init_pair(2,COLOR_BLUE,COLOR_WHITE);
init_pair(3, COLOR_GREEN, COLOR_BLUE);
init_pair(4, COLOR_RED, COLOR_BLUE);
curs_set(0);
noecho();
keypad(stdscr,TRUE);
touchwin(stdscr);
wrefresh(stdscr);
}