mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Revamp the jobs builtin
darcs-hash:20051211233001-ac50b-24547ca41d4db05f87d59dd3e396c3190a66ef89.gz
This commit is contained in:
parent
28dd48a76a
commit
5262f3ce99
5 changed files with 180 additions and 87 deletions
244
builtin.c
244
builtin.c
|
@ -73,6 +73,18 @@
|
||||||
/**
|
/**
|
||||||
Table of all builtins
|
Table of all builtins
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
JOBS_DEFAULT,
|
||||||
|
JOBS_PRINT_PID,
|
||||||
|
JOBS_PRINT_COMMAND,
|
||||||
|
JOBS_PRINT_GROUP,
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
static hash_table_t builtin;
|
static hash_table_t builtin;
|
||||||
|
|
||||||
int builtin_out_redirect;
|
int builtin_out_redirect;
|
||||||
|
@ -2400,25 +2412,103 @@ static int cpu_use( job_t *j )
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void builtin_jobs_print( job_t *j, int mode, int header )
|
||||||
|
{
|
||||||
|
process_t *p;
|
||||||
|
switch( mode )
|
||||||
|
{
|
||||||
|
case JOBS_DEFAULT:
|
||||||
|
{
|
||||||
|
|
||||||
|
if( header )
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Print table header before first job
|
||||||
|
*/
|
||||||
|
sb_append( sb_out, L"Job\tGroup\t");
|
||||||
|
#ifdef HAVE__PROC_SELF_STAT
|
||||||
|
sb_append( sb_out, L"CPU\t" );
|
||||||
|
#endif
|
||||||
|
sb_append( sb_out, L"State\tCommand\n" );
|
||||||
|
}
|
||||||
|
|
||||||
|
sb_printf( sb_out, L"%d\t%d\t", j->job_id, j->pgid );
|
||||||
|
|
||||||
|
#ifdef HAVE__PROC_SELF_STAT
|
||||||
|
sb_printf( sb_out, L"%d%%\t", cpu_use(j) );
|
||||||
|
#endif
|
||||||
|
sb_append2( sb_out, job_is_stopped(j)?L"stopped\t":L"running\t",
|
||||||
|
// job_is_completed(j)?L"completed\t":L"unfinished\t",
|
||||||
|
j->command, L"\n", (void *)0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
case JOBS_PRINT_GROUP:
|
||||||
|
{
|
||||||
|
if( header )
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Print table header before first job
|
||||||
|
*/
|
||||||
|
sb_append( sb_out, L"Group\n");
|
||||||
|
}
|
||||||
|
sb_printf( sb_out, L"%d\n", j->pgid );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case JOBS_PRINT_PID:
|
||||||
|
{
|
||||||
|
if( header )
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Print table header before first job
|
||||||
|
*/
|
||||||
|
sb_append( sb_out, L"Procces\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
for( p=j->first_process; p; p=p->next )
|
||||||
|
{
|
||||||
|
sb_printf( sb_out, L"%d\n", p->pid );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case JOBS_PRINT_COMMAND:
|
||||||
|
{
|
||||||
|
if( header )
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Print table header before first job
|
||||||
|
*/
|
||||||
|
sb_append( sb_out, L"Command\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
for( p=j->first_process; p; p=p->next )
|
||||||
|
{
|
||||||
|
sb_printf( sb_out, L"%ls\n", p->argv[0] );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Builtin for printing running jobs
|
Builtin for printing running jobs
|
||||||
*/
|
*/
|
||||||
static int builtin_jobs( wchar_t **argv )
|
static int builtin_jobs( wchar_t **argv )
|
||||||
{
|
{
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
DEFAULT,
|
|
||||||
PRINT_PID,
|
|
||||||
PRINT_COMMAND
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
int argc=0;
|
int argc=0;
|
||||||
job_t *j;
|
|
||||||
int found=0;
|
int found=0;
|
||||||
int mode=DEFAULT;
|
int mode=JOBS_DEFAULT;
|
||||||
|
|
||||||
|
job_t *print_me=0;
|
||||||
|
|
||||||
|
|
||||||
argc = builtin_count_args( argv );
|
argc = builtin_count_args( argv );
|
||||||
|
|
||||||
woptind=0;
|
woptind=0;
|
||||||
|
@ -2436,6 +2526,14 @@ static int builtin_jobs( wchar_t **argv )
|
||||||
L"command", no_argument, 0, 'c'
|
L"command", no_argument, 0, 'c'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
|
{
|
||||||
|
L"group", no_argument, 0, 'g'
|
||||||
|
}
|
||||||
|
,
|
||||||
|
{
|
||||||
|
L"last", no_argument, 0, 'l'
|
||||||
|
}
|
||||||
|
,
|
||||||
{
|
{
|
||||||
0, 0, 0, 0
|
0, 0, 0, 0
|
||||||
}
|
}
|
||||||
|
@ -2446,7 +2544,7 @@ static int builtin_jobs( wchar_t **argv )
|
||||||
|
|
||||||
int opt = wgetopt_long( argc,
|
int opt = wgetopt_long( argc,
|
||||||
argv,
|
argv,
|
||||||
L"pc",
|
L"pclg",
|
||||||
long_options,
|
long_options,
|
||||||
&opt_index );
|
&opt_index );
|
||||||
if( opt == -1 )
|
if( opt == -1 )
|
||||||
|
@ -2472,13 +2570,33 @@ static int builtin_jobs( wchar_t **argv )
|
||||||
|
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
mode=PRINT_PID;
|
mode=JOBS_PRINT_PID;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
mode=PRINT_COMMAND;
|
mode=JOBS_PRINT_COMMAND;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'g':
|
||||||
|
mode=JOBS_PRINT_GROUP;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'l':
|
||||||
|
{
|
||||||
|
job_t *j;
|
||||||
|
for( j=first_job; j; j=j->next )
|
||||||
|
{
|
||||||
|
if( j->constructed )
|
||||||
|
{
|
||||||
|
print_me = j;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
// builtin_print_help( argv[0], sb_err );
|
// builtin_print_help( argv[0], sb_err );
|
||||||
|
|
||||||
|
@ -2487,58 +2605,16 @@ static int builtin_jobs( wchar_t **argv )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( mode==DEFAULT )
|
if( woptind < argc-1 )
|
||||||
{
|
{
|
||||||
|
sb_append2( sb_err, argv[0], L": zero or one arguments\n", (void *)0 );
|
||||||
for( j= first_job; j; j=j->next )
|
return 1;
|
||||||
{
|
|
||||||
/*
|
|
||||||
Ignore unconstructed jobs, i.e. ourself.
|
|
||||||
*/
|
|
||||||
if( j->constructed /*&& j->skip_notification*/ )
|
|
||||||
{
|
|
||||||
if( !found )
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
Print table header before first job
|
|
||||||
*/
|
|
||||||
sb_append( sb_out, L"Job\tGroup\t");
|
|
||||||
#ifdef HAVE__PROC_SELF_STAT
|
|
||||||
sb_append( sb_out, L"CPU\t" );
|
|
||||||
#endif
|
|
||||||
sb_append( sb_out, L"State\tCommand\n" );
|
|
||||||
}
|
|
||||||
|
|
||||||
found = 1;
|
|
||||||
|
|
||||||
sb_printf( sb_out, L"%d\t%d\t", j->job_id, j->pgid );
|
|
||||||
|
|
||||||
#ifdef HAVE__PROC_SELF_STAT
|
|
||||||
sb_printf( sb_out, L"%d%%\t", cpu_use(j) );
|
|
||||||
#endif
|
|
||||||
sb_append2( sb_out, job_is_stopped(j)?L"stopped\t":L"running\t",
|
|
||||||
// job_is_completed(j)?L"completed\t":L"unfinished\t",
|
|
||||||
j->command, L"\n", (void *)0 );
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( !found )
|
|
||||||
{
|
|
||||||
sb_append2( sb_out, argv[0], L": There are no running jobs\n", (void *)0 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if( woptind == argc-1 )
|
||||||
{
|
{
|
||||||
long pid;
|
long pid;
|
||||||
wchar_t *end;
|
wchar_t *end;
|
||||||
job_t *j;
|
|
||||||
|
|
||||||
if( woptind != argc-1 )
|
|
||||||
{
|
|
||||||
sb_append2( sb_err, argv[0], L": Expected exactly one argument\n", (void *)0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
errno=0;
|
errno=0;
|
||||||
pid=wcstol( argv[woptind], &end, 10 );
|
pid=wcstol( argv[woptind], &end, 10 );
|
||||||
if( errno || *end )
|
if( errno || *end )
|
||||||
|
@ -2548,30 +2624,44 @@ static int builtin_jobs( wchar_t **argv )
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
j = job_get_from_pid( pid );
|
print_me = job_get_from_pid( pid );
|
||||||
if( !j )
|
if( !print_me )
|
||||||
{
|
{
|
||||||
sb_printf( sb_err, L"%ls: No suitable job: %d\n", argv[0], pid );
|
sb_printf( sb_err, L"%ls: No suitable job: %d\n", argv[0], pid );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
process_t *p;
|
|
||||||
for( p=j->first_process; p; p=p->next )
|
|
||||||
{
|
|
||||||
switch( mode )
|
|
||||||
{
|
|
||||||
case PRINT_PID:
|
|
||||||
{
|
|
||||||
sb_printf( sb_out, L"%d\n", p->pid );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case PRINT_COMMAND:
|
}
|
||||||
{
|
|
||||||
sb_printf( sb_out, L"%ls\n", p->argv[0] );
|
/*
|
||||||
break;
|
Do not babble if not interactive
|
||||||
}
|
*/
|
||||||
|
if( builtin_out_redirect )
|
||||||
|
found=1;
|
||||||
|
|
||||||
|
if( !print_me )
|
||||||
|
{
|
||||||
|
job_t *j;
|
||||||
|
|
||||||
|
for( j= first_job; j; j=j->next )
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Ignore unconstructed jobs, i.e. ourself.
|
||||||
|
*/
|
||||||
|
if( j->constructed /*&& j->skip_notification*/ )
|
||||||
|
{
|
||||||
|
builtin_jobs_print( j, mode, !found );
|
||||||
|
found = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if( !found )
|
||||||
|
{
|
||||||
|
sb_append2( sb_out, argv[0], L": There are no running jobs\n", (void *)0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
builtin_jobs_print( print_me, mode, !found );
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -997,7 +997,6 @@ g++, javac, java, gcj, lpr, doxygen, whois, find)
|
||||||
- The jobs builtin should be able to give information on a specific job, such as the pids of the processes in the job
|
- The jobs builtin should be able to give information on a specific job, such as the pids of the processes in the job
|
||||||
- Syntax highlighting should mark cd to non-existing directories as an error
|
- Syntax highlighting should mark cd to non-existing directories as an error
|
||||||
- the code for printing the prompt should know about the most common escape sequences
|
- the code for printing the prompt should know about the most common escape sequences
|
||||||
- block builtin
|
|
||||||
- redo the jobs command
|
- redo the jobs command
|
||||||
- wait shellscript
|
- wait shellscript
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,20 @@
|
||||||
\section jobs jobs - print currently running jobs
|
\section jobs jobs - print currently running jobs
|
||||||
|
|
||||||
\subsection jobs-synopsis
|
\subsection jobs-synopsis
|
||||||
<tt>jobs</tt>
|
<tt>jobs [OPTIONS] [PID]</tt>
|
||||||
|
|
||||||
\subsection jobs-description Description
|
\subsection jobs-description Description
|
||||||
The <tt>jobs</tt> builtin causes fish to print a list of the currently
|
The <tt>jobs</tt> builtin causes fish to print a list of the currently
|
||||||
running jobs and their status.
|
running jobs and their status.
|
||||||
|
|
||||||
On systems that supports this feature, jobs will also print the CPU
|
jobs accepts the following switches:
|
||||||
usage of each job since the last command was executed. The CPU usage
|
|
||||||
is expressed as a percentage of full CPU activity. Note that on
|
- <tt>-l</tt> or <tt>--last</tt> only the last job to be started is printed
|
||||||
|
- <tt>-g</tt> or <tt>--group</tt> only print the group id of each job
|
||||||
|
- <tt>-c</tt> or <tt>--command</tt> print the commandname for each process in all jobs
|
||||||
|
- <tt>-p</tt> or <tt>--process</tt> print the procces id for each process in all jobs
|
||||||
|
|
||||||
|
On systems that supports this feature, jobs will print the CPU usage
|
||||||
|
of each job since the last command was executed. The CPU usage is
|
||||||
|
expressed as a percentage of full CPU activity. Note that on
|
||||||
multiprocessor systems, the total activity may be more than 100\%.
|
multiprocessor systems, the total activity may be more than 100\%.
|
||||||
|
|
5
event.c
5
event.c
|
@ -463,8 +463,6 @@ static void event_fire_delayed()
|
||||||
blocked = new_blocked;
|
blocked = new_blocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while( sig_list[active_list].count > 0 )
|
while( sig_list[active_list].count > 0 )
|
||||||
{
|
{
|
||||||
signal_list_t *lst;
|
signal_list_t *lst;
|
||||||
|
@ -518,7 +516,6 @@ static void event_fire_delayed()
|
||||||
|
|
||||||
void event_fire( event_t *event )
|
void event_fire( event_t *event )
|
||||||
{
|
{
|
||||||
//int is_event_old = is_event;
|
|
||||||
is_event++;
|
is_event++;
|
||||||
|
|
||||||
if( event && (event->type == EVENT_SIGNAL) )
|
if( event && (event->type == EVENT_SIGNAL) )
|
||||||
|
@ -556,7 +553,7 @@ void event_fire( event_t *event )
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
is_event--;// = is_event_old;
|
is_event--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue