本文整理汇总了C++中pid2jid函数的典型用法代码示例。如果您正苦于以下问题:C++ pid2jid函数的具体用法?C++ pid2jid怎么用?C++ pid2jid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pid2jid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig)
{
int tmppid = 1;
int st;
while( tmppid > 0 ) { // default tmppid is 1.
tmppid = waitpid(-1, &st, WNOHANG | WUNTRACED); // wait all children and with WNOHANG | WUNTRACED.
if(tmppid > 0) { // When child processes returns PID.
if(WIFEXITED(st)) // When the child exits.
deletejob(jobs, tmppid);
else {
if(WIFSIGNALED(st)) {
if(WTERMSIG(st) == 2) // If signal is 2(that is SIGINT)
printf("Job [%d] (%d) terminated by signal %d\n", pid2jid(tmppid), tmppid, WTERMSIG(st));
deletejob(jobs, tmppid);
}
else if(WIFSTOPPED(st)) { // When child processes are stopped.
getjobpid(jobs, tmppid)->state = ST; // Change state.
printf("Job [%d] (%d) stopped by signal %d\n", pid2jid(tmppid), tmppid, WSTOPSIG(st));
}
}
}
}
}
示例2: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP, SIGTSTP, SIGTTIN or SIGTTOU signal. The
* handler reaps all available zombie children, but doesn't wait
* for any other currently running children to terminate.
*/
void
sigchld_handler(int sig)
{
pid_t pid;
int status;
struct job_t* job;
while ((pid = waitpid(-1, &status, WNOHANG | WUNTRACED)) > 0) {
if (WIFSIGNALED(status)) {
if (WTERMSIG(status) == SIGINT) {
printf("Job [%d] (%d) terminated by signal %d\n",
pid2jid(pid), pid, WTERMSIG(status));
deletejob(job_list, pid);
}
}
else if (WIFSTOPPED(status)) {
job = getjobpid(job_list, pid);
job->state = ST;
printf("Job [%d] (%d) stopped by signal %d\n",
pid2jid(pid), pid, WSTOPSIG(status));
}
else
deletejob(job_list, pid);
}
if (pid == -1 && errno != ECHILD)
unix_error("waitpid error");
return;
}
示例3: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP, SIGTSTP, SIGTTIN or SIGTTOU signal. The
* handler reaps all available zombie children, but doesn't wait
* for any other currently running children to terminate.
*/
void
sigchld_handler(int sig)
{
pid_t pid;
int status;
while((pid = waitpid(-1, &status, WNOHANG | WUNTRACED)) > 0){
if(pid == fgpid(job_list)){
if(tcgetpgrp(STDIN_FILENO) != shell_pid) {
tcsetpgrp(STDIN_FILENO, shell_pid);
}
}
if(WIFEXITED(status)){
deletejob(job_list, pid);
} else if(WIFSIGNALED(status)){
printf("Job [%d] (%d) terminated by signal %d\n",
pid2jid(pid), pid, WTERMSIG(status));
deletejob(job_list, pid);
} else if (WIFSTOPPED(status)) {
printf("Job [%d] (%d) stopped by signal %d\n",
pid2jid(pid), pid, WSTOPSIG(status));
getjobpid(job_list, pid)->state = ST;
}
}
return;
}
示例4: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig)
{
int status;
pid_t pid;
while ((pid = waitpid(fgpid(jobs), &status, WNOHANG|WUNTRACED)) > 0) {
if (WIFSTOPPED(status)){
//change state if stopped
getjobpid(jobs, pid)->state = ST;
int jid = pid2jid(pid);
printf("Job [%d] (%d) Stopped by signal %d\n", jid, pid, WSTOPSIG(status));
}
else if (WIFSIGNALED(status)){
//delete is signaled
int jid = pid2jid(pid);
printf("Job [%d] (%d) terminated by signal %d\n", jid, pid, WTERMSIG(status));
deletejob(jobs, pid);
}
else if (WIFEXITED(status)){
//exited
deletejob(jobs, pid);
}
}
return;
}
示例5: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig)
{
int olderrno = errno;
sigset_t mask_all, prev_all;
pid_t pid;
int status;
Sigfillset(&mask_all);
while ((pid = waitpid(-1, &status, WNOHANG|WUNTRACED)) > 0) {
Sigprocmask(SIG_BLOCK, &mask_all, &prev_all); /* Block Signals*/
if (WIFEXITED(status)) { /* Exit normally */
deletejob(jobs, pid);
}
if (WIFSIGNALED(status)) { /* C-c SIGINT */
printf("Job [%d] (%d) terminated by signal 2\n", pid2jid(pid), pid);
deletejob(jobs, pid); /* Note: printf first, then deletejob */
}
if (WIFSTOPPED(status)) { /* C-z SIGTSTP */
printf("Job [%d] (%d) stopped by signal 20\n", pid2jid(pid), pid);
getjobpid(jobs, pid)->state = ST;
}
Sigprocmask(SIG_SETMASK, &prev_all, NULL); /* Unblock Signals*/
}
errno = olderrno;
return;
}
示例6: builtincont
void builtincont(struct cmdline_tokens *tok, int state){
if (tok->argc < 2){
// app_error("Usage: %s [%jid/pid]\n", tok->argv[0]);
return;
}
pid_t pid;
/* JID */
if (tok->argv[1][0]=='%'){
int jid = atoi((char *)(tok->argv[1] + sizeof(char)));
pid = jid2pid(jid);
if (!pid)
app_error("No such jid \n");
}
else{
/* PID case */
pid = atoi(tok->argv[1]);
if (!pid2jid(pid))
app_error("No such pid \n");
}
/* Common to both JID & PID */
Kill(-pid, SIGCONT);
changestate(job_list, pid, state);
if (state==BG){
printf("[%d] (%d) %s\n", pid2jid(pid), pid,
getjobpid(job_list,pid)->cmdline);
}
if (state==FG){
wait_for_fg(pid);
}
}
示例7: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP, SIGTSTP, SIGTTIN or SIGTTOU signal. The
* handler reaps all available zombie children, but doesn't wait
* for any other currently running children to terminate.
*/
void sigchld_handler(int sig) {
int status;
pid_t pid;
while((pid = waitpid(-1, &status, WNOHANG | WUNTRACED)) > 0) {
if(WIFEXITED(status)) {
/* if a child job terminated normally */
deletejob(job_list, pid);
} else if(WIFSIGNALED(status)) {
/* if a child job terminated by signal */
printf("Job [%d] (%d) terminated by signal %d\n",
pid2jid(pid), pid, WTERMSIG(status));
deletejob(job_list, pid);
} else if(WIFSTOPPED(status)) {
/* if a child job is stopped, we should also update its status */
printf("Job [%d] (%d) stopped by signal %d\n",
pid2jid(pid), pid, WSTOPSIG(status));
getjobpid(job_list, pid) -> state = ST;
}
}
return;
}
示例8: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig)
{
int pid,status;
while ((pid=waitpid(-1, &status, WNOHANG | WUNTRACED))>0)
{
/*If there is any child which is still running then parent will not wait for them and retuens the pids and status of reaped child with MACRO "WNOHANG".*/
/* Also if there are any stopped ot terminated child then parent will reap them immediately with MACRO "WUNTRACED"*/
if (WIFEXITED(status))/* MACRO "WIFEXITED" returns true if child terminated normally*/
{
deletejob(jobs, pid); /* delete job from jobtable when terminated*/
}
else if (WIFSIGNALED(status))/* MACRO "WIFSIGNALED" returns true if reaped child is terminated*/
{
printf("Job [%d] (%d) terminated by signal %d\n", pid2jid(pid), pid, WTERMSIG(status));/*MACRO "WTERMSIG" gives by which signal child is terminated*/
deletejob(jobs, pid); /* delete job from jobtable when terminated*/
}
else if (WIFSTOPPED(status))/* MACRO "WIFSTOPPED" returns true if reaped child is stopped*/
{
getjobpid(jobs, pid)->state = ST; /* If child process receives stop signal then it will change state of child process*/
printf("Job [%d] (%d) stopped by signal %d\n", pid2jid(pid), pid, WSTOPSIG(status)); /*MACRO "WSTOPSIG" gives by which signal child is stopped*/
}
}
return;
}
示例9: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP, SIGTSTP, SIGTTIN or SIGTTOU signal. The
* handler reaps all available zombie children, but doesn't wait
* for any other currently running children to terminate.
*/
void
sigchld_handler(int sig)
{
int status;
pid_t pid;
while((pid = waitpid(-1, &status, WUNTRACED | WNOHANG)) > 0)
{
// If child exited normally, delete job from list
if(WIFEXITED(status))
deletejob(job_list, pid);
// If child terminated because of uncaught signal, delete job from list
else if(WIFSIGNALED(status))
{
printf("Job [%d] (%d) terminated by signal %d\n",
pid2jid(pid), pid, WTERMSIG(status));
deletejob(job_list, pid);
}
// If child was stopped change status to ST
else if(WIFSTOPPED(status))
{
printf("Job [%d] (%d) stopped by signal %d\n",
pid2jid(pid), pid, WSTOPSIG(status));
getjobpid(job_list, pid) -> state = ST;
}
}
return;
}
示例10: sigchld_handler
void sigchld_handler(int sig)
{
pid_t pid = 0;
struct job_t *nowjob = 0;
int status;
while((pid = waitpid(-1, &status, WNOHANG | WUNTRACED)) > 0)//handle all stopped or terminated children
{
if(WIFEXITED(status))
{
// printf("pid [%d] terminated normally\n",pid);
deletejob(jobs,pid);
}
else if(WIFSIGNALED(status))
{
printf("Job [%d] (%d) terminated by signal %d\n",pid2jid(pid),pid,WTERMSIG(status));
deletejob(jobs,pid);
}
else if(WIFSTOPPED(status))
{
printf("Job [%d] (%d) stopped by signal %d\n", pid2jid(pid), pid, WSTOPSIG(status));
nowjob = getjobpid(jobs,pid);
nowjob->state = ST;
}
}
if((errno != ECHILD) && (errno != 0))
{
unix_error("waitpid error");
}
return;
}
示例11: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig) {
pid_t pid;
int status;
// Reap all the child process.
while ((pid = waitpid(-1, &status, WNOHANG | WUNTRACED)) > 0) {
//Handle with the 3 situation in this handler together.
if (WIFSIGNALED(status)) {
printf("Job [%d] (%d) terminated by Signal %d\n", pid2jid(pid),
pid,
WTERMSIG(status));
deletejob(jobs, pid);
} else if (
WIFSTOPPED(status)) {
struct job_t *job = getjobpid(jobs, pid);
if (job == NULL) {
printf("sigchld: Get job error.\n");
return;
}
job->state = ST;
printf("Job [%d] (%d) stopped by Signal %d\n", pid2jid(pid), pid,
WEXITSTATUS(status));
} else if (
WIFEXITED(status)) {
deletejob(jobs, pid);
}
//printf("Handler reaped child %d\n", (int)pid);
}
return;
}
示例12: sigchld_handler
void sigchld_handler(int sig)
{
int pid=0;
int status=-1;
do{ //continually reap as many children as possible, deleting them from the job list
pid=waitpid(-1,&status,WNOHANG|WUNTRACED);
if(pid>0)//first time
{
if(WIFEXITED(status)){//child terminated normally, easy to handle, just delete it from the job list
deletejob(jobs,pid);
}
else
if(WIFSIGNALED(status)){ //what if the process was terminated by another process?
if(WTERMSIG(status)==2)
printf("Job [%d] (%d) terminated by signal %d\n", pid2jid(pid), pid, WTERMSIG(status));
deletejob(jobs,pid);
}
else if(WIFSTOPPED(status)){ //what if the process was stopped by another process?
getjobpid(jobs, pid)->state=ST;
printf("Job [%d] (%d) stopped by signal %d\n", pid2jid(pid), pid, WSTOPSIG(status));
}
}
}
while(pid>0);
}
示例13: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP, SIGTSTP, SIGTTIN or SIGTTOU signal. The
* handler reaps all available zombie children, but doesn't wait
* for any other currently running children to terminate.
*/
void sigchld_handler(int sig) {
int status;
pid_t pid;
int olderrno = errno; // store errno in handler
/*
* Reap child with the pid if the child is stopped or terminated
* If a child is terminated normally, delete the child from the job list
* If a child is stopped by a signal, set the job status as stopped
* If a child is terminated by a signal that was not caught, delete the child from the job list
*/
while ((pid = waitpid(-1, &status, WNOHANG|WUNTRACED)) > 0) {
if (WIFEXITED(status)) {
deletejob(job_list, pid); // the child ternimated normally
} else if (WIFSTOPPED(status)) {
/*
* Avoid printf() in handler, use helper function to write the output to stdout
*/
sio_puts("Job [");
sio_putl(pid2jid(pid));
sio_puts("] (");
sio_putl(pid);
sio_puts(") stopped by signal ");
sio_putl(WSTOPSIG(status));
sio_puts("\n");
getjobpid(job_list, pid) -> state = ST; // the child was stopped by a signal
} else if (WIFSIGNALED(status)) { // the child was terminated by a signal that was not caught
/*
* Avoid printf() in handler, use helper function to write the output to stdout
*/
sio_puts("Job [");
sio_putl(pid2jid(pid));
sio_puts("] (");
sio_putl(pid);
sio_puts(") terminated by signal ");
sio_putl(WTERMSIG(status));
sio_puts("\n");
deletejob(job_list, pid);
}
}
errno = olderrno;
return;
}
示例14: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig)
{
/*
int status;
waitpid(-1, &status, 0);
return;
*/
//printf("...in sigchild\n");
fflush(stdout);
int status = 1;
pid_t pid;
while ( ( pid = waitpid(-1, &status, WNOHANG | WUNTRACED) ) > 0 )
{
if (WIFSTOPPED(status))
{
int jid = pid2jid(pid);
getjobpid(jobs, pid)->state = ST;
printf("%s [%d] (%d) %s %d %s", "Job", jid, pid, "stopped by signal", SIGSTOP, "\n");
}
else
{
int jid = pid2jid(pid);
int jdel = deletejob(jobs, pid);
if (jdel)
{
if (sig != 17)
{
//printf("MADE IT!\n");
printf("%s [%d] (%d) %s %d %s", "Job", jid, pid, "terminated by signal", SIGINT, "\n");
}
}
else
{
printf("error deleting job\n");
fflush(stdout);
exit(1);
}
}
}
if (pid == -1)
{
//printf("...no processes\n");
}
else if (pid < -1)
{
printf("error in sigchild\n");
fflush(stdout);
exit(1);
}
return;
}
示例15: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig)
{
int status;
if (verbose) printf ("sigchld_handler: entering\n");
/* wait until some child is terminated */
pid_t pid_ch, jid_ch ;
while ((pid_ch = waitpid (-1, &status, WUNTRACED | WNOHANG)) > 0) { // wait any terminated child
jid_ch = pid2jid (pid_ch);
if (verbose) printf ("sigchld_handler: Job [%d] (%d) deleted\n", jid_ch, pid_ch);
if (WIFEXITED (status)) { // case 1: child process terminated normally
if (verbose) printf ("sigchld_handler: Job [%d] (%d) terminates OK (status 0)\n", jid_ch, pid_ch);
deletejob (jobs, pid_ch);
}
else if (WIFSIGNALED (status)) { // case 2: child process terminated via a signal that was not caught
deletejob (jobs, pid_ch);
printf ("Job [%d] (%d) terminated by signal %d\n", jid_ch, pid_ch, WTERMSIG (status));
}
else if (WIFSTOPPED (status)) { // case 3: child process stopped
struct job_t *stopped = getjobpid (jobs, pid_ch);
stopped->state = ST;
printf ("Job [%d] (%d) stopped by signal %d\n", jid_ch, pid_ch, WSTOPSIG (status));
}
}
if (verbose) printf ("sigchld_handler: exiting\n");
return;
}